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 12»»

Predict the outcome of the SQL statements Expand / Collapse
Author
Message
Posted Wednesday, September 1, 2010 8:38 PM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Friday, September 3, 2010 4:19 AM
Points: 158, Visits: 72
Comments posted to this topic are about the item Predict the outcome of the SQL statements
Post #979251
Posted Wednesday, September 1, 2010 10:23 PM
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: Yesterday @ 8:49 PM
Points: 3,024, Visits: 2,628
I would prefer that you gave a better answer/reason for the result of the first expression being 1 instead of 2. The reason is not simply because of the use of the DECIMAL datatype. It is because no precision and scale was specified. The default precision is 18 and the default scale is 0. This results in rounding to zero decimal places (i.e. it effectively results in an integer). In this situation, the floor function simply returns the value (it doesn't need to do anything since the DECIMAL (18,0) value is the same as the result of the floor function).


Post #979280
Posted Thursday, September 2, 2010 12:11 AM


SSC-Addicted

SSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-Addicted

Group: General Forum Members
Last Login: Friday, July 5, 2013 11:51 PM
Points: 488, Visits: 336
Thanks for explaining it clearly. I had missed this point.

Saurabh Dwivedy
___________________________________________________________

My Blog: http://tinyurl.com/dwivedys

For better, quicker answers, click on the following...
http://www.sqlservercentral.com/articles/Best+Practices/61537

Be Happy!
Post #979313
Posted Thursday, September 2, 2010 12:24 AM
SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Wednesday, October 15, 2014 1:05 PM
Points: 1,913, Visits: 794
Yes Happycat...Good Explanation.

Select ceiling(Convert(decimal(2,1),1.09)) will give you the result 2.


Regards,
Rals
.
Post #979315
Posted Thursday, September 2, 2010 1:09 AM
SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Friday, October 17, 2014 1:15 AM
Points: 1,804, Visits: 496
Thanks for the better explanation of the Decimal function, as I was very confused about that one statement!

Intersting question though.
Post #979322
Posted Thursday, September 2, 2010 2:29 AM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Tuesday, August 27, 2013 4:28 AM
Points: 1,248, Visits: 779
Thanks happycat for the detailed explanation, makes perfect sense now.

_____________________________________________________________________
"The difficult tasks we do immediately, the impossible takes a little longer"
Post #979341
Posted Thursday, September 2, 2010 3:53 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 6:39 AM
Points: 13,238, Visits: 11,015
Nice question, but the explanation could be better, as Happycat already demonstrated.



How to post forum questions.
Need an answer? No, you need a question.
What’s the deal with Excel & SSIS?

Member of LinkedIn. My blog at LessThanDot.

MCSA SQL Server 2012 - MCSE Business Intelligence
Post #979380
Posted Thursday, September 2, 2010 6:56 AM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Tuesday, October 7, 2014 2:36 PM
Points: 2,818, Visits: 2,565
Great follow on explanation. Thanks.
Post #979486
Posted Thursday, September 2, 2010 9:05 AM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: Administrators
Last Login: 2 days ago @ 3:49 PM
Points: 31,161, Visits: 15,607
Added a bit to the explanation, as per Happycat59






Follow me on Twitter: @way0utwest

Forum Etiquette: How to post data/code on a forum to get the best help
Post #979625
Posted Thursday, September 2, 2010 10:17 AM


SSCoach

SSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoach

Group: General Forum Members
Last Login: Yesterday @ 3:06 PM
Points: 17,805, Visits: 15,716
Thanks for the question.



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


SQL RNNR

Posting Performance Based Questions - Gail Shaw
Post #979685
« Prev Topic | Next Topic »

Add to briefcase 12»»

Permissions Expand / Collapse