Tsql - Case Date Compare
I am trying to compare a date in SQL and create a new field to allow me to group the results by Todays date and other date(s). I am converting both dates to CHAR. However i am gett
Solution 1:
Why not compare the dates directly?
CASEWHEN DATEDIFF(day, FieldDate, GETDATE()) =0THEN1ELSE0ENDAS tmpDate
Solution 2:
Move the field to the front:
select tmpDate =CASEWHENConvert(Char(8), FieldDate, 103) =Convert(Char(8), GetDate(), 103) Then'1'ELSE'0'END
Post a Comment for "Tsql - Case Date Compare"