我有以下SQL代码:
Declare @MyDate datetime
Select @MyDate = ISNULL(T.requireddate, Convert(DateTime, '01/01/2013', 101))
from myTable T
where T.somekey = somevalue
Select @MyDate
输出为NULL。为什么它是01/01/2013
?
答案 0 :(得分:0)
你确定select会返回任何行吗?
如果该选择没有返回任何行,则@MyDate将为null
尝试
Select T.requireddate, ISNULL(T.requireddate, Convert(DateTime, '01/01/2013', 101))
from myTable T
where T.somekey = somevalue