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 01, 2010 8:38 PM
 SSC-Enthusiastic Group: General Forum Members Last Login: Friday, September 03, 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 01, 2010 10:23 PM
 SSCrazy Group: General Forum Members Last Login: Wednesday, April 16, 2014 9:21 PM Points: 2,842, Visits: 2,423
 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 02, 2010 12:11 AM
 SSC-Addicted Group: General Forum Members Last Login: Friday, July 05, 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/dwivedysFor better, quicker answers, click on the following... http://www.sqlservercentral.com/articles/Best+Practices/61537Be Happy!
Post #979313
 Posted Thursday, September 02, 2010 12:24 AM
 SSCommitted Group: General Forum Members Last Login: Wednesday, November 20, 2013 4:08 AM Points: 1,849, Visits: 775
 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 02, 2010 1:09 AM
 SSCommitted Group: General Forum Members Last Login: Thursday, April 10, 2014 1:38 AM Points: 1,615, Visits: 446
 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 02, 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 02, 2010 3:53 AM
 SSChampion Group: General Forum Members Last Login: Today @ 4:35 AM Points: 12,208, Visits: 9,172
 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 02, 2010 6:56 AM
 SSCrazy Group: General Forum Members Last Login: Monday, April 14, 2014 2:16 PM Points: 2,812, Visits: 2,543
Post #979486
 Posted Thursday, September 02, 2010 9:05 AM
 SSC-Dedicated Group: Administrators Last Login: Yesterday @ 11:24 AM Points: 32,781, Visits: 14,942