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 Monday, November 1, 2010 10:24 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 #1014270
Posted Tuesday, November 2, 2010 12:16 AM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Monday, June 16, 2014 9:38 AM
Points: 2,163, Visits: 2,189
Nice question, thanks!

Though I think the explanation left a little to be desired. It isn't just that the decimal type was used, it was that the decimal type was used and no precision/scale was specified, so the number got rounded down to 1.0 when it was converted.

For example this results in the same thing as all of your float examples:

select Ceiling(convert(decimal(2, 1), 1.09))

Because with a scale of one specified it gets rounded to 1.1 before it goes to ceiling.
Post #1014294
Posted Tuesday, November 2, 2010 3:35 AM
SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Today @ 9:46 AM
Points: 1,737, Visits: 6,338
Knew the answer but had a brain fart and clicked the wrong option, oops!

UMG Developer is right about the explanation.
Post #1014337
Posted Tuesday, November 2, 2010 6:39 AM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Yesterday @ 3:24 PM
Points: 1,393, Visits: 478
Good question but I think a better explaination is:
the default of decimal without parameters is (18,0) thus making 1.09 -> 1 and then the ceiling of 1 is 1
Post #1014419
Posted Tuesday, November 2, 2010 6:59 AM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Thursday, April 18, 2013 5:41 AM
Points: 71, Visits: 49
Thank you Old Hand. I knew the ceiling function brought you up to the next integer, but I couldn't figure out why the decimal was any different than the float on this one! You're explanation was what I was missing. For some reason I thought the default precision was 2, not 0. I'll be sure to remember that the next time I use a decimal data type.
Post #1014432
Posted Tuesday, November 2, 2010 7:06 AM
SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Today @ 9:46 AM
Points: 1,737, Visits: 6,338
I hope one thing that everybody has learned from these questions is that you should never rely on default precision for anything - you will inevitably get it wrong sooner or later
Post #1014441
Posted Tuesday, November 2, 2010 7:38 AM


SSCrazy Eights

SSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy Eights

Group: General Forum Members
Last Login: Today @ 4:54 PM
Points: 8,689, Visits: 9,223
Good question, but as some have already noted the explanation is a bit lacking.

Also, the question was made too easy by the absence of the All 2s option as an answer choice - anyone who knows what ceiling means can eliminate all answers but the correct one with knowing anything at all about decimal or its default precision.


Tom
Post #1014472
Posted Tuesday, November 2, 2010 9:55 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: 2 days ago @ 11:27 PM
Points: 3,901, Visits: 3,634
Tom.Thomson (11/2/2010)
Good question, but as some have already noted the explanation is a bit lacking.

Also, the question was made too easy by the absence of the All 2s option as an answer choice - anyone who knows what ceiling means can eliminate all answers but the correct one with knowing anything at all about decimal or its default precision.


Yes, I agree. The best wrong answer was missing.
Post #1014642
Posted Tuesday, November 2, 2010 2:26 PM


SSC-Insane

SSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-Insane

Group: General Forum Members
Last Login: Today @ 3:27 PM
Points: 21,631, Visits: 15,289
Thanks for the question.



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


SQL RNNR

Posting Performance Based Questions - Gail Shaw
Posting Data Etiquette - Jeff Moden
Hidden RBAR - Jeff Moden
VLFs and the Tran Log - Kimberly Tripp
Post #1014887
Posted Wednesday, November 3, 2010 1:01 PM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 9:28 AM
Points: 13,570, Visits: 10,447
Good question, although it was more about convert than about ceiling.
A link to the msdn page for convert and decimal:

http://msdn.microsoft.com/en-us/library/ms187928(SQL.90).aspx (convert)

http://msdn.microsoft.com/en-us/library/ms187746.aspx (decimal/numeric)

The last page describes the gotcha of this question in the explanation of the scale.




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 #1015516
« Prev Topic | Next Topic »

Add to briefcase 12»»

Permissions Expand / Collapse