SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


ISNULL


ISNULL

Author
Message
rfr.ferrari
rfr.ferrari
SSCrazy
SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)

Group: General Forum Members
Points: 2123 Visits: 13639
Thanks for question, JestersGrind !!!

Thanks for your comments Hugo and Tom!!!


rfr.ferrari
DBA - SQL Server 2008
MCITP | MCTS

remember is live or suffer twice!
the period you fastest growing is the most difficult period of your life!

JestersGrind
JestersGrind
Hall of Fame
Hall of Fame (3.9K reputation)Hall of Fame (3.9K reputation)Hall of Fame (3.9K reputation)Hall of Fame (3.9K reputation)Hall of Fame (3.9K reputation)Hall of Fame (3.9K reputation)Hall of Fame (3.9K reputation)Hall of Fame (3.9K reputation)

Group: General Forum Members
Points: 3903 Visits: 1585
Hugo,

Thanks for the feedback. I agree that the explanation could be better, but through my research on the topic, I couldn't find an adequate explanation for this behavior. Still, I thought this nuance to SQL was interesting enough to form a QotD.

Thanks,

Greg



JestersGrind
JestersGrind
Hall of Fame
Hall of Fame (3.9K reputation)Hall of Fame (3.9K reputation)Hall of Fame (3.9K reputation)Hall of Fame (3.9K reputation)Hall of Fame (3.9K reputation)Hall of Fame (3.9K reputation)Hall of Fame (3.9K reputation)Hall of Fame (3.9K reputation)

Group: General Forum Members
Points: 3903 Visits: 1585
Archie,

You are correct. That was an over sight on my part. I didn't test it with SQL 2000. The question should have stated that this was for SQL 2005 and higher. My apologies.

Thanks,

Greg



JTSash
JTSash
SSCommitted
SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)

Group: General Forum Members
Points: 1604 Visits: 2032
L' Eomot Inversé (11/23/2011)
That explicit documentation doesn't give any explanation either. Since MONEY and DECIMAL and NUMERIC are all exact numeric types (see the Data Types topic in BoL) with decimal fractions, there should be some justification for the different behaviours but no reason is given anywhere for this difference in behaviour; why does MONEY, and exact numeric with decimal fraction, behave in this respect like the exact numerics that don't have decimal fractions instead of like the other exact numeric types with decimal fractions? I think that "for some reason" is the only reason that can be offered on the basis of BoL (although of course "because the people who invented this MONEY kludge hadn't a clue" might be some people's guess as to the reason); of course it is not necessary to offer a reason in explanations for QoTD - and in some cases (as illustrated by the potential guessed explanation suggested above) it may better not to. Why don't we have a reason? Not because the question author failed in his explanation - indeed he very accurately (albeit somewhat obliquely) pointed out that there is no documented reason - but because MS has not chosen to tell us the reason (of course there's no reason why it should, although for technical decisions which look this bizarre most technology companies do give reasons).


I believe that MONEY is stored internally as BIGINT, thus the difference in behavior.
Rose Bud
Rose Bud
SSCommitted
SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)

Group: General Forum Members
Points: 1775 Visits: 1062
.
L' Eomot Inversé (11/23/2011)

...of course it is not necessary to offer a reason in explanations for QoTD...Why don't we have a reason? Not because the question author failed in his explanation - indeed he very accurately (albeit somewhat obliquely) pointed out that there is no documented reason...


Well said. Great question!
.
chrisfradenburg
chrisfradenburg
SSCrazy
SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)

Group: General Forum Members
Points: 2922 Visits: 2076
BOL states that this happens for numeric and decimal so I'm betting it has something to do with the fact that those are the two data types that can take a precision and scale when declared. I tried playing around with making the scale 0 and that didn't work but the check may be such that it doesn't even check the scale.
SQLRNNR
SQLRNNR
SSC Guru
SSC Guru (64K reputation)SSC Guru (64K reputation)SSC Guru (64K reputation)SSC Guru (64K reputation)SSC Guru (64K reputation)SSC Guru (64K reputation)SSC Guru (64K reputation)SSC Guru (64K reputation)

Group: General Forum Members
Points: 64963 Visits: 18570
JestersGrind (11/23/2011)
Archie,

You are correct. That was an over sight on my part. I didn't test it with SQL 2000. The question should have stated that this was for SQL 2005 and higher. My apologies.

Thanks,

Greg



Though it was not stated, we should consider the question to be on current database engine unless otherwise specified. 2000 is quite old and if we are posting a question relative to 2000 then we should explicitly state that it is for 2000. In other words, I don't think it was an oversight.:-D



Jason AKA CirqueDeSQLeil
I have given a name to my pain...
MCM SQL Server, MVP


SQL RNNR

Posting Performance Based Questions - Gail Shaw

SQLRNNR
SQLRNNR
SSC Guru
SSC Guru (64K reputation)SSC Guru (64K reputation)SSC Guru (64K reputation)SSC Guru (64K reputation)SSC Guru (64K reputation)SSC Guru (64K reputation)SSC Guru (64K reputation)SSC Guru (64K reputation)

Group: General Forum Members
Points: 64963 Visits: 18570
I thought it was interesting that the money works and decimal does not. I did a little more testing. Based on that testing, I would almost say that the ISNULL check implicitly converts the string to a float(or money) for the money data type for the comparison but does not do that for the decimal.


DECLARE @Integer INT
,@Float FLOAT
,@Decimal DECIMAL(18,6)
,@Bit BIT
,@Money MONEY
,@String VARCHAR(20) = CAST('' AS FLOAT)

SELECT ISNULL(@Integer,@String),'Int'
SELECT ISNULL(@Float,@String),'Float'
SELECT ISNULL(@Decimal,@String),'Decimal'
SELECT ISNULL(@Bit,@String),'Bit'
SELECT ISNULL(@Money,@String),'Money'




It makes no sense that the decimal behaves this way when the money doesn't.



Jason AKA CirqueDeSQLeil
I have given a name to my pain...
MCM SQL Server, MVP


SQL RNNR

Posting Performance Based Questions - Gail Shaw

David P Fisher
David P Fisher
Say Hey Kid
Say Hey Kid (668 reputation)Say Hey Kid (668 reputation)Say Hey Kid (668 reputation)Say Hey Kid (668 reputation)Say Hey Kid (668 reputation)Say Hey Kid (668 reputation)Say Hey Kid (668 reputation)Say Hey Kid (668 reputation)

Group: General Forum Members
Points: 668 Visits: 215
gary.mazzone (11/23/2011)
If you comment out Select ISNULL(@Money,'') you get the error on Select ISNULL(@Decimal,'')

[color=#red]Error converting data type varchar to numeric.[/color]

So shouldn't the answer be more then 1?



Absolutely agree !!

The impossible can be done at once, miracles may take a little longer :-)
OzYbOi d(-_-)b
OzYbOi d(-_-)b
SSCommitted
SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)

Group: General Forum Members
Points: 1696 Visits: 778
Tks for the question.

Certainly a little curious as to why only the Decimal behaves in this manor... But this is something that I have run across before in a shop where implicit conversions of data was the normal practice. Crazy

Happy Thanksgiving to all the (US of) Americans! :-D
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search