|
|
|
UDP Broadcaster
      
Group: General Forum Members
Last Login: Monday, June 10, 2013 7:59 PM
Points: 1,491,
Visits: 3,010
|
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Today @ 8:30 AM
Points: 1,418,
Visits: 267
|
|
Interesting answer. I tried this without looking anything up, and got some of it wrong. Then I ran the queries ... and in my case, the queries that were stated as failures in your answer did indeed fail. BUT although several answers did not return errors, NONE actually returned the quoted string: they all seemed to return NULL. Did anyone else get similar results?
|
|
|
|
|
SSCommitted
      
Group: General Forum Members
Last Login: Friday, January 11, 2013 8:20 AM
Points: 1,608,
Visits: 373
|
|
Hi,
I tried it as well and got exactly the predicted results. You must, however, be aware that result sets ("Date is Null"; "Date is Nu") and the messages ("Option 1:", errors, etc.) are shown in separate windows.
Best regards, Dietmar Weickert.
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Today @ 8:30 AM
Points: 1,418,
Visits: 267
|
|
Yes, my mistake Dietmar! I think I was half-asleep!
Ken.
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Thursday, January 24, 2013 9:59 PM
Points: 1,354,
Visits: 1,299
|
|
I almost selected option 6 and then when I double checked my answers, I noticed the tricky char(10) which isn't big enough to fit the whole 'Date is Null' string. It needed to be char(12) to give the right results.
Very sneaky question but I did get this one.
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Yesterday @ 7:16 AM
Points: 1,046,
Visits: 575
|
|
Nice one, Noticed that when you use your case statement as per below then you get the "Date is Null" results as you do not have your else statement.
SELEC CASE WHEN CONVERT(CHAR(10),@MyDate,101) IS NULL THEN 'Date is Null' END AS MyDate
What you don't know won't hurt you but what you know will make you plan to know better
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Tuesday, June 04, 2013 10:52 AM
Points: 1,043,
Visits: 2,945
|
|
Which of these seven queries will return "Date is Null"? (select all that apply)
Was that a zero-based list? 
Semper in excretia, sumus solum profundum variat
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Tuesday, August 07, 2012 6:59 AM
Points: 1,386,
Visits: 823
|
|
cengland0 (11/9/2009) I almost selected option 6 and then when I double checked my answers, I noticed the tricky char(10) which isn't big enough to fit the whole 'Date is Null' string. It needed to be char(12) to give the right results.
Very sneaky question but I did get this one.
yep, i missed that. phooey.
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Today @ 7:32 AM
Points: 1,059,
Visits: 1,396
|
|
duda (11/9/2009) Nice one, Noticed that when you use your case statement as per below then you get the "Date is Null" results as you do not have your else statement.
SELEC[T] CASE WHEN CONVERT(CHAR(10),@MyDate,101) IS NULL THEN 'Date is Null' END AS MyDate
True, but you don't get the date when @MyDate is not null either.
All of the queries are examples of trying to return @MyDate when it's not null, and "Date is Null" otherwise.
|
|
|
|
|
SSC Eights!
      
Group: General Forum Members
Last Login: Today @ 6:24 AM
Points: 892,
Visits: 936
|
|
Good question. I missed the char(10) limitation. I did not know that COALESCE does not limit output size while ISNULL does.
coalesce(convert(char(10),@MyDate,101),'Date is Null') = not limited to 10 characters IsNull(convert(char(10),@MyDate,101),'Date is Null') = limited to 10 characters
Now just have to try and remember this 
David
|
|
|
|