Reputation: 57
I have a field that is a DATETIME
field that may be null. If that field is null, I want to return the date from 30 days ago. I have tried the following:
SELECT ISNULL(lastupdatedatetime, GETDATE() - 30) from .......
SELECT CASE WHEN lastupdatedatetime is null then GETDATE() - 30 ELSE lastupdatedatetime from ....
In both cases I keep getting 2000-01-01 00:00:00:000
How can I get the result from GETDATE()
that I'm looking for when lastupdatedatetime
is null?
Upvotes: 0
Views: 1423
Reputation: 2937
Try this:
SELECT (CASE WHEN lastupdatedatetime is null then DATEADD(day,-30,GETDATE()) ELSE lastupdatedatetime from ..
That should work.
Upvotes: 1