# Predict the outcome of the SQL statements

• bazzkar

SSC Veteran

Points: 270

Comments posted to this topic are about the item Predict the outcome of the SQL statements

• happycat59

One Orange Chip

Points: 29189

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).

• Saurabh Dwivedy

SSCommitted

Points: 1881

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!
• ralm

Hall of Fame

Points: 3156

Yes Happycat...Good Explanation.

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

[font="Verdana"]Regards,
Rals
[/font].
• Michael Riemer

SSCertifiable

Points: 5096

Thanks for the better explanation of the Decimal function, as I was very confused about that one statement!

Intersting question though.

• DugyC

Hall of Fame

Points: 3804

Thanks happycat for the detailed explanation, makes perfect sense now.

_____________________________________________________________________
[font="Comic Sans MS"]"The difficult tasks we do immediately, the impossible takes a little longer"[/font]

• Koen Verbeeck

SSC Guru

Points: 258965

Nice question, but the explanation could be better, as Happycat already demonstrated.

Need an answer? No, you need a question
My blog at https://sqlkover.com.
MCSE Business Intelligence - Microsoft Data Platform MVP

• Daniel Bowlin

SSC-Dedicated

Points: 34566

• Steve Jones - SSC Editor

SSC Guru

Points: 719176

Added a bit to the explanation, as per Happycat59

• SQLRNNR

SSC Guru

Points: 281243

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[/url]
Learn Extended Events

• Julie Breutzmann

Hall of Fame

Points: 3607

Thanks for the question and for Happycat59's further explanation. I learned something new.

Julie

• TomThomson

SSC Guru

Points: 104773

Nice fun question.

Tom

• zymos

SSCommitted

Points: 1960

Interesting question.

Viewing 13 posts - 1 through 13 (of 13 total)