Question

I have the following TSQL code:

Declare @MyDate datetime

Select @MyDate = ISNULL(T.requireddate, Convert(DateTime, '01/01/2013', 101)) 
from myTable T 
where T.somekey = somevalue

Select @MyDate

The output is NULL. Why isn't it 01/01/2013?

Was it helpful?

Solution

Are you sure that select returns any rows?

If that select returns no rows then @MyDate would be null

Try

Select T.requireddate, ISNULL(T.requireddate, Convert(DateTime, '01/01/2013', 101)) 
from myTable T 
where T.somekey = somevalue
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top