TSQL - Case Date Compare

I am trying to compare a date in SQL and create a new field so that I can group the results by Todays date and another date (s). I convert both dates to CHAR. However, I get an expression error next to = and). This is for the SSRS report.

There is a rather complicated SQL statement, and I'm just trying to add this extra statement to help with grouping.

Here is an example.

Case WHEN Convert (Char (8), FieldDate, 103) = Convert (Char (8), GetDate (), 103) Then tmpDate = '1' ELSE tmpDate = '0' END

This leads to incorrect sntax near '=' This leads to incorrect sntax near ')'

thanks

+1
source share
3 answers

Why not compare dates directly?

CASE WHEN DATEDIFF(day, FieldDate, GETDATE()) = 0 THEN 1 ELSE 0 END AS tmpDate 
+3
source

Move the field forward:

 select tmpDate = CASE WHEN Convert(Char(8), FieldDate, 103) = Convert(Char(8), GetDate(), 103) Then '1' ELSE '0' END 
+2
source

If your example is from your code (copy / paste), "Then tmpDate -" 1 "will not work. Do you put a hyphen instead of an equal sign?

+1
source

All Articles