November 13, 2013 at 10:40 am
This may be a simple one for you guys, but I just don't know the correct syntax.
I have the following CASE statement:
CASE WHEN ModifiedDate > DateClosed THEN 1 ELSE 0 END as FieldName
The ClosedDate field sometimes is NULL and the modifieddate field has value. I will get a false 1 since the modifieddate will always be larger than the ClosedField that has a NULL.
How can I tell it when the DateClosed field is not null?
Thanks.
Hope that made sense.
UPDATE: Never mind, I was able to make it work.
November 13, 2013 at 12:06 pm
What approach did you take?
My option would be something like this:
CASE WHEN ModifiedDate > ISNULL( DateClosed, 0) THEN 1 ELSE 0 END as FieldName
November 13, 2013 at 2:09 pm
DarthBurrito (11/13/2013)
I will get a false 1 since the modifieddate will always be larger than the ClosedField that has a NULL.
How can I tell it when the DateClosed field is not null?
No, you won't. The condition won't be "true" if the column is NULL, so you will get a 0 result. (If the column is NULL, the condition result will also be "NULL", which is not "true".
SQL DBA,SQL Server MVP(07, 08, 09) "Money can't buy you happiness." Maybe so, but it can make your unhappiness a LOT more comfortable!
November 13, 2013 at 2:21 pm
Hi what was Your solution? It would be good if you can share one.
I may have similar situation in future.
Thanks
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply