Recent PostsRecent Posts Popular TopicsPopular Topics
 Home Search Members Calendar Who's On

 Predict the outcome of the SQL statements Rate Topic Display Mode Topic Options
Author
 Message
 Posted Wednesday, September 1, 2010 8:38 PM
 SSC-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 Group: General Forum Members Last Login: Yesterday @ 8:01 PM Points: 3,529, Visits: 3,064
 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 Group: General Forum Members Last Login: Friday, June 3, 2016 3:40 AM Points: 488, Visits: 340
 Thanks for explaining it clearly. I had missed this point. Saurabh Dwivedy___________________________________________________________My Blog: http://tinyurl.com/dwivedysFor better, quicker answers, click on the following... http://www.sqlservercentral.com/articles/Best+Practices/61537Be Happy!
Post #979313
 Posted Thursday, September 2, 2010 12:24 AM
 SSCrazy Group: General Forum Members Last Login: Friday, March 4, 2016 7:14 AM Points: 2,130, Visits: 834
 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
 SSCrazy Group: General Forum Members Last Login: Thursday, November 24, 2016 1:31 AM Points: 2,585, Visits: 621
 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 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
 SSCoach Group: General Forum Members Last Login: 2 days ago @ 2:09 AM Points: 15,501, Visits: 13,163
 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 SQLKover. MCSA SQL Server 2012 - MCSE Business Intelligence
Post #979380
 Posted Thursday, September 2, 2010 6:56 AM
 SSCrazy Group: General Forum Members Last Login: Saturday, September 17, 2016 8:01 AM Points: 2,834, Visits: 2,629
Post #979486
 Posted Thursday, September 2, 2010 9:05 AM
 SSC-Dedicated Group: Administrators Last Login: Yesterday @ 12:17 PM Points: 34,363, Visits: 18,583