|
|
|
SSC Veteran
      
Group: General Forum Members
Last Login: Wednesday, May 15, 2013 2:13 AM
Points: 298,
Visits: 574
|
|
|
|
|
|
SSChasing Mays
      
Group: General Forum Members
Last Login: Friday, January 11, 2013 12:41 PM
Points: 621,
Visits: 297
|
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Yesterday @ 7:47 AM
Points: 1,400,
Visits: 6,886
|
|
Does anyone know why it behaves like this? It appears to be at odds with any documentation I can find.
BrainDonor.
BrainDonor Linkedin
|
|
|
|
|
SSC Veteran
      
Group: General Forum Members
Last Login: Wednesday, May 15, 2013 2:13 AM
Points: 298,
Visits: 574
|
|
The documentation is slightly different; 2005 BOL says that when "replacement_value" is returned, it will be implicitly converted to the type of "check_expression" while 2000 BOL just demands both expressions to be of same type.
This was the last straw for me, I haven't typed "ISNULL" into a code window since but switched to always using COALESCE.
Which I was expecting someone would mention. Perhaps there are circumstances where usage of ISNULL is warranted, but such use would require good commenting as most think of ISNULL and COALESCE as being equal.
COALESCE returns the full 10-character "replacement_value" in both versions.
|
|
|
|
|
SSChasing Mays
      
Group: General Forum Members
Last Login: Wednesday, May 15, 2013 10:09 AM
Points: 648,
Visits: 684
|
|
Wow, that is just bizarre. I wouldn't have called that in a million years, and I don't feel the least bit bad about getting it wrong. Great question!
----- a haiku...
NULL is not zero NULL is not an empty string NULL is the unknown
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Yesterday @ 4:56 AM
Points: 1,256,
Visits: 4,253
|
|
| Yes, I found this bizarre behaviour the first time I encountered it. Just did a quick experiment on a SQL 2008 installation and I see it still does the same there, so guess we're probably stuck with this now. Pity, because it's utterly non-intuitive that NULL should have a size at all!
|
|
|
|
|
SSCommitted
      
Group: General Forum Members
Last Login: Yesterday @ 2:04 AM
Points: 1,968,
Visits: 1,819
|
|
Also a void string take 1 CHAR:
SET CONCAT_NULL_YIELDS_NULL ON SELECT ISNULL('abcd'+''+null,'1234567890')
Result: 123456
|
|
|
|
|
Old Hand
      
Group: General Forum Members
Last Login: Tuesday, March 26, 2013 3:14 AM
Points: 345,
Visits: 503
|
|
as well ..
SET CONCAT_NULL_YIELDS_NULL ON SELECT ISNULL('abcd'+NULL+NULL,'1234567890') Results : 123456
-- Sabya
|
|
|
|
|
SSCommitted
      
Group: General Forum Members
Last Login: Yesterday @ 2:04 AM
Points: 1,968,
Visits: 1,819
|
|
The question is: it is a BUG? ... or it is by design? ... or both: it is a BUG by design!
Try this:
DECLARE @v char(10) SET CONCAT_NULL_YIELDS_NULL ON SELECT ISNULL('abcd'+@v,'1234567890')
RESULT: 1234567890
This behavior is all right!
|
|
|
|
|
Hall of Fame
       
Group: General Forum Members
Last Login: Yesterday @ 2:11 PM
Points: 3,108,
Visits: 2,114
|
|
ahhh ... just another case of getting 'caught' by an 'implicit' converstion !
Regards Rudy Komacsar Senior Database Administrator
"Ave Caesar! - Morituri te salutamus."
|
|
|
|