|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Yesterday @ 5:50 PM
Points: 1,308,
Visits: 3,899
|
|
|
|
|
|
SSCommitted
      
Group: General Forum Members
Last Login: Yesterday @ 9:44 PM
Points: 1,852,
Visits: 987
|
|
Non Sense question.I thought correct answer. means it will through error.but due to hint given by him i did not consider date and got wrong. am not happy with question and answer.
Malleswarareddy I.T.Analyst MCITP(70-451)
|
|
|
|
|
UDP Broadcaster
      
Group: General Forum Members
Last Login: Friday, May 10, 2013 3:15 AM
Points: 1,476,
Visits: 1,943
|
|
Okay not the best question. However i wouldnt go as far to say it was nonsence. It shows that you cant mix different datatypes in a conditional order by without thinking about conversions.
I do however dislike the
WHEN @sortby = 'String1' THEN String2 WHEN @sortby = 'String2' THEN String1
part. Sorting by 'String1' and then using column String2 (and vice versa) doesnt really add anything. It makes you think that its a trick question. So its easy to focus on that part instead.
So next time, no "trick" code to obscure what your trying to show ppl. Its really not needed.
/T
|
|
|
|
|
SSCommitted
      
Group: General Forum Members
Last Login: Yesterday @ 12:56 AM
Points: 1,972,
Visits: 1,822
|
|
I should remember implicit cast using CASE clause. Good question. I refreshed implicit cast. In sql2000, it gives error also with SET @sortby='Date1'. (Syntax error converting datetime from character string.), not in sql2005.
|
|
|
|
|
UDP Broadcaster
      
Group: General Forum Members
Last Login: Friday, May 10, 2013 3:15 AM
Points: 1,476,
Visits: 1,943
|
|
Carlo Romagnano (11/16/2010) I should remember implicit cast using CASE clause. Good question. I refreshed implicit cast. In sql2000, it gives error also with SET @sortby='Date1'. (Syntax error converting datetime from character string.), not in sql2005.
No it doesnt Well its not related to it being SQL2000. Probably some language issue. Works fine on mine.
/T
|
|
|
|
|
Mr or Mrs. 500
      
Group: General Forum Members
Last Login: Monday, August 13, 2012 10:04 AM
Points: 554,
Visits: 861
|
|
this is the one of the way to handle those error.
DECLARE @sortby VARCHAR(10) SET @sortby='String2'
SELECT String1, String2, Date1 FROM ( SELECT 'StringValue1', '2', CONVERT(datetime,'1 July 2010 00:01:00') UNION ALL SELECT 'StringValue2', '1', CONVERT(datetime,'2 July 2010 00:02:00') ) AS a(String1,String2,Date1) ORDER BY CASE WHEN @sortby = 'String1' THEN String2 WHEN @sortby = 'String2' THEN String1 end, CASE WHEN @sortby = 'Date1' THEN Date1 END
Thanks & Regards Deepak.A
|
|
|
|
|
SSCommitted
      
Group: General Forum Members
Last Login: Yesterday @ 12:56 AM
Points: 1,972,
Visits: 1,822
|
|
tommyh (11/16/2010)
Carlo Romagnano (11/16/2010) I should remember implicit cast using CASE clause. Good question. I refreshed implicit cast. In sql2000, it gives error also with SET @sortby='Date1'. (Syntax error converting datetime from character string.), not in sql2005.No it doesnt  Well its not related to it being SQL2000. Probably some language issue. Works fine on mine. /T Also, I should remember "set language 'us_english'".
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: 2 days ago @ 1:02 AM
Points: 1,277,
Visits: 1,609
|
|
|
|
|
|
SSCommitted
      
Group: General Forum Members
Last Login: Yesterday @ 8:39 AM
Points: 1,609,
Visits: 1,103
|
|
I thought it was an interesting question as well - currently more people have it wrong than right which shows that we can still be surprised at the "behind the scenes" antics of SQL Server.
Please don't describe questions as "nonsense", people take taime to set them and always have good intentions when they do so. It doesn't help your case if you can't spell "nonsense" either.
|
|
|
|
|
UDP Broadcaster
      
Group: General Forum Members
Last Login: Friday, May 10, 2013 3:15 AM
Points: 1,476,
Visits: 1,943
|
|
Richard Warr (11/16/2010) I thought it was an interesting question as well - currently more people have it wrong than right which shows that we can still be surprised at the "behind the scenes" antics of SQL Server.
Please don't describe questions as "nonsense", people take taime to set them and always have good intentions when they do so. It doesn't help your case if you can't spell "nonsense" either.
I know this wasnt directed at me (i dont think so anyway)... however.
You shouldnt complain about spelling. This is an international site and as long as you can understand what someone else writes... its okay. Perfect spelling/grammar is rare.
Also considering your own "taime" spelling... well... mistakes happen 
/T (non native english speaker)
|
|
|
|