Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Between Date

Author  Topic 

BendJoe
Posting Yak Master

128 Posts

Posted - 2010-08-19 : 13:31:42
I have a where clause in which I am filtering between a date range.
(Date between @startdate and @enddate or(@startdate is null and @enddate is null))
the @startdate and @enddtae is optional.
What is the correct filter to get the results between the two date ranges also need to consider the possibility of either or both of these parameters being null.
Thanks

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-08-19 : 13:49:51
[code]WHERE (Date >= @Startdate or @StartDate is null)
AND (Date < @EndDate + 1 or @EndDate is null)[/code]

assuming you dont pass time part with dates and you want data for @EndDate inclusive

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -