|
|
|
SSCoach
         
Group: General Forum Members
Last Login: Monday, May 20, 2013 1:07 PM
Points: 18,733,
Visits: 12,332
|
|
|
|
|
|
Mr or Mrs. 500
      
Group: General Forum Members
Last Login: Tuesday, August 10, 2010 6:29 PM
Points: 513,
Visits: 82
|
|
Good Question.
|
|
|
|
|
SSCommitted
      
Group: General Forum Members
Last Login: Friday, May 17, 2013 2:53 AM
Points: 1,529,
Visits: 359
|
|
nice info about isnull and coalesce... thanks
|
|
|
|
|
SSC Eights!
      
Group: General Forum Members
Last Login: Thursday, May 16, 2013 5:30 AM
Points: 861,
Visits: 1,436
|
|
Very nice question. Fortunately for me, I've come to know the differences of both functions while studying for the MCTS exam.
The best of all are these discussions about the question of the day. You always get to learn something new and read the opinions of more qualified professionals than me.
Best regards,
Andre Guerreiro Neto
Database Analyst http://www.softplan.com.br MCITPx1/MCTSx2
|
|
|
|
|
SSC-Enthusiastic
      
Group: General Forum Members
Last Login: Thursday, May 02, 2013 11:47 AM
Points: 151,
Visits: 277
|
|
Hi, Thanks for posting this. I have few clarification on COALESCE result type and i am confused the type conversion.
Consider the case below.
--Case 1 DECLARE @STR int SET @STR=NULL SELECT COALESCE(@STR,null,CAST('2010-05-05' AS DATETIME))
Result: 2010-05-05 00:00:00.000
--Case 2 DECLARE @STR2 int SET @STR2=NULL SELECT COALESCE(@STR2,null,CAST('ABCD' AS varchar(10)))
Result: Error: Msg 245, Level 16, State 1, Line 9 Conversion failed when converting the varchar value 'ABCD' to data type int.
--Case 3 DECLARE @STR2 int SET @STR2=NULL SELECT COALESCE(@STR2,null,CAST('2222' AS varchar(10)))
Result: 2222
In case1, @str is int type, but expression 2 in COALESCE is datetime. But i except the output to be 40301 which is the int value for date 2010-05-05 when following rule on case2 and case 3?
How case1 is evaluated?
Also what exactly mean by "1. Data type determination of the resulting expression - ISNULL uses the first parameter type, COALESCE follows the CASE expression rules and returns type of value with highest precedence"
Thanks in advance Gopi
|
|
|
|
|
Mr or Mrs. 500
      
Group: General Forum Members
Last Login: Wednesday, July 25, 2012 9:04 PM
Points: 542,
Visits: 187
|
|
|
|
|
|
SSC-Addicted
      
Group: General Forum Members
Last Login: Monday, May 20, 2013 9:43 AM
Points: 469,
Visits: 193
|
|
| Nice question on the COALASCE function that ignores the data type and size hence returning the entire string. Thanks
|
|
|
|