I do not know BasicDatePicker control, but try this:
select * from MyTable
where (Division = @Division) and
((@BasicDatePicker1 is null) or
(@BasicDatePicker2 is null) or
((Date1 >= @BasicDatePicker1) and
(Date2 <= @BasicDatePicker2)))
select * from my table
where ((@BasicDatePicker1 IS NULL OR @BasicDatePicker2) AND Division=@Division)
OR (Division=@Division and Date1>=@BasicDatePicker1 and Date2<=@BasicDatePicker2)
salim20001
Member
154 Points
507 Posts
Help with selecting
May 08, 2012 12:47 AM|LINK
Hi, I need your help
I had a gridview, One dropdownlist Division and 2 basicdatepicker,
in my table i have:
Division Date1 Date2
I want to select * from my table where
Division=@Division (from my dropdown list) and (the 2 basicdatepicker not filled)
OR
(Division=@Division and Date1>=@BasicDatePicker1 and Date2<=@BasicDatePicker2)
Can you help me with this SQL statement ?
imobsuz
Participant
1278 Points
195 Posts
Re: Help with selecting
May 08, 2012 02:16 AM|LINK
Hi,
I do not know BasicDatePicker control, but try this:
select * from MyTable where (Division = @Division) and ((@BasicDatePicker1 is null) or (@BasicDatePicker2 is null) or ((Date1 >= @BasicDatePicker1) and (Date2 <= @BasicDatePicker2)))Hope this helps.
yrb.yogi
Star
14460 Points
2402 Posts
Re: Help with selecting
May 08, 2012 06:29 AM|LINK
.Net All About
tusharrs
Contributor
3230 Points
668 Posts
Re: Help with selecting
May 08, 2012 06:41 AM|LINK
select * from [my table]
where
( (Division=@Division) and (@BasicDatePicker1 is null and @BasicDatePicker2 is null) )
or
( (Division=@Division) and (Date1 >= @BasicDatePicker1 and Date2 <= @BasicDatePicker2) )
( Mark as Answer if it helps you out )
View my Blog
salim20001
Member
154 Points
507 Posts
Re: Help with selecting
May 08, 2012 04:56 PM|LINK
a basicdatepicker is just a textbox that had a date, however
salim20001
Member
154 Points
507 Posts
Re: Help with selecting
May 08, 2012 04:58 PM|LINK
Thanks, but if I try @BasicDatePicker is null the system(.NET) gives me an error (date cannt be null or date must be >1750 and <9999)
christiandev
Star
8607 Points
1841 Posts
Re: Help with selecting
May 08, 2012 05:34 PM|LINK
use a nullable DateTime - DateTime?
http://stackoverflow.com/questions/221732/datetime-null-value
Regards, Christiandev (@chrisdev80), MCPD Web (2 & 4) & MCTS Windows (www.ScoreDonkey.com)
imobsuz
Participant
1278 Points
195 Posts
Re: Help with selecting
May 08, 2012 05:58 PM|LINK
Salim20001,
How are you passing the parameters?
I think you better post the code used.
salim20001
Member
154 Points
507 Posts
Re: Help with selecting
May 09, 2012 05:49 PM|LINK
Thanks,
How can use a nullable Datetime ?
christiandev
Star
8607 Points
1841 Posts
Re: Help with selecting
May 10, 2012 09:29 AM|LINK
use:
DateTime? myDate; <- notice the question mark - also, look at the link I posted above.
Regards, Christiandev (@chrisdev80), MCPD Web (2 & 4) & MCTS Windows (www.ScoreDonkey.com)