Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase ««123»»

ISNULL Expand / Collapse
Author
Message
Posted Wednesday, November 23, 2011 6:38 AM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Monday, October 13, 2014 8:02 AM
Points: 1,258, Visits: 13,556
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!
Post #1210953
Posted Wednesday, November 23, 2011 6:41 AM


Hall of Fame

Hall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of Fame

Group: General Forum Members
Last Login: Tuesday, May 14, 2013 1:42 PM
Points: 3,487, Visits: 1,581
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




Post #1210956
Posted Wednesday, November 23, 2011 6:43 AM


Hall of Fame

Hall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of Fame

Group: General Forum Members
Last Login: Tuesday, May 14, 2013 1:42 PM
Points: 3,487, Visits: 1,581
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




Post #1210958
Posted Wednesday, November 23, 2011 7:21 AM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Friday, October 17, 2014 6:31 AM
Points: 1,281, Visits: 1,691
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.
Post #1211003
Posted Wednesday, November 23, 2011 7:45 AM


UDP Broadcaster

UDP BroadcasterUDP BroadcasterUDP BroadcasterUDP BroadcasterUDP BroadcasterUDP BroadcasterUDP BroadcasterUDP Broadcaster

Group: General Forum Members
Last Login: Friday, September 19, 2014 7:15 AM
Points: 1,447, Visits: 1,059
.
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!
.
Post #1211027
Posted Wednesday, November 23, 2011 8:31 AM
SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Thursday, October 9, 2014 8:27 AM
Points: 1,639, Visits: 1,984
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.
Post #1211078
Posted Wednesday, November 23, 2011 8:33 AM


SSCoach

SSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoach

Group: General Forum Members
Last Login: Yesterday @ 3:24 PM
Points: 17,812, Visits: 15,737
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.




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


SQL RNNR

Posting Performance Based Questions - Gail Shaw
Post #1211080
Posted Wednesday, November 23, 2011 8:37 AM


SSCoach

SSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoach

Group: General Forum Members
Last Login: Yesterday @ 3:24 PM
Points: 17,812, Visits: 15,737
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
Post #1211085
Posted Wednesday, November 23, 2011 8:52 AM


SSChasing Mays

SSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing Mays

Group: General Forum Members
Last Login: Thursday, February 7, 2013 7:38 AM
Points: 616, 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
Post #1211107
Posted Wednesday, November 23, 2011 8:55 AM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Thursday, January 31, 2013 8:53 AM
Points: 1,176, 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.

Happy Thanksgiving to all the (US of) Americans!
Post #1211113
« Prev Topic | Next Topic »

Add to briefcase ««123»»

Permissions Expand / Collapse