Вопрос

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?

Это было полезно?

Решение

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
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top