Sunday, November 23, 2008

Ever needed to-do this in SQL?

select * from ATABLE

where [SomeDate]=@A_DATE_YOU_WANT_TO_LOOKFO

Now suppose that you want to ignore times as SQL Server's DateTime object stores the time along with the date.

You can modify the query to-do just this.

select * from ATABLE

CAST(FLOOR(CAST( [SomeDate] AS float)) AS datetime) = @A_DATE_YOU_WANT_TO_LOOKFO

 

Obviously the variable @A_DATE_YOU_WANT_TO_LOOKFO should  have its time set to midnight,  but this works great.

Sunday, November 23, 2008 9:31:46 AM UTC  #    Comments [0]  | 

Theme design by Jelle Druyts

Pick a theme: