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: 29186

    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


    Points: 1881

    Thanks for explaining it clearly. I had missed this point.

    Saurabh Dwivedy

    My Blog:

    For better, quicker answers, click on the following...

    Be Happy!
  • ralm

    Hall of Fame

    Points: 3117

    Yes Happycat...Good Explanation.

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

  • Michael Riemer

    SSCarpal Tunnel

    Points: 4795

    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: 258909

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

    Need an answer? No, you need a question
    My blog at
    MCSE Business Intelligence - Microsoft Data Platform MVP

  • Daniel Bowlin


    Points: 34566

    Great follow on explanation. Thanks.

  • Steve Jones - SSC Editor

    SSC Guru

    Points: 715107

    Added a bit to the explanation, as per Happycat59


    SSC Guru

    Points: 281210

    Thanks for the question.

    Jason...AKA CirqueDeSQLeil
    I have given a name to my pain...MCM SQL Server, MVP
    Posting Performance Based Questions - Gail Shaw[/url]
    Learn Extended Events

  • Julie Breutzmann

    Hall of Fame

    Points: 3587

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


  • TomThomson

    SSC Guru

    Points: 104763

    Nice fun question.


  • zymos


    Points: 1960

    Interesting question.

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

You must be logged in to reply to this topic. Login to reply