-1

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?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
DeveloperM
  • 1,129
  • 7
  • 17
  • 30
  • Because `DateTime` is `null`, too. – AdamL May 06 '14 at 14:44
  • Hmmm, lots of down-votes. Still trying to understand my error. I'd be grateful for an explanation. Thanks to all. – DeveloperM May 06 '14 at 14:52
  • 1
    What does `SELECT T.RequiredDate FROM ..` return? Do you really get a `NULL` ?? And what's the **datatype** of `RequiredDate` in your table? – marc_s May 06 '14 at 14:52

1 Answers1

0

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
paparazzo
  • 44,497
  • 23
  • 105
  • 176
  • Ahh. You are correct. That IS the problem, although I fully expected it to return one row. Thank you, @Blam, for taking the time to help me. Now to investigate where my row went.... – DeveloperM May 06 '14 at 14:58