Log in
::
Register
::
Not logged in
Home
Tags
Articles
Editorials
Stairways
Forums
Scripts
Videos
Blogs
QotD
Books
Ask SSC
SQL Jobs
Training
Authors
About us
Contact us
Newsletters
Write for us
Recent Posts
Recent Posts
Popular Topics
Popular Topics
Home
Search
Members
Calendar
Who's On
Home
»
Article Discussions
»
Article Discussions by Author
»
Discuss content posted by SQL Buzz
»
Predict the outcome of the SQL statements
13 posts, Page 1 of 2
1
2
»»
Predict the outcome of the SQL statements
Rate Topic
Display Mode
Topic Options
Author
Message
bazzkar
bazzkar
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
happycat59
happycat59
Posted Wednesday, September 01, 2010 10:23 PM
SSCrazy
Group: General Forum Members
Last Login: Today @ 6:10 AM
Points: 2,470,
Visits: 2,062
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
Saurabh Dwivedy
Saurabh Dwivedy
Posted Thursday, September 02, 2010 12:11 AM
SSC-Addicted
Group: General Forum Members
Last Login: Thursday, January 05, 2012 2:05 AM
Points: 488,
Visits: 335
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!
Post #979313
rals
rals
Posted Thursday, September 02, 2010 12:24 AM
SSCommitted
Group: General Forum Members
Last Login: 2 days ago @ 1:13 AM
Points: 1,720,
Visits: 746
Yes Happycat...Good Explanation.
Select ceiling(Convert(decimal(2,1),1.09)) will give you the result
2
.
Regards,
Rals
.
Post #979315
Michael Riemer
Michael Riemer
Posted Thursday, September 02, 2010 1:09 AM
Ten Centuries
Group: General Forum Members
Last Login: Thursday, May 16, 2013 2:10 AM
Points: 1,237,
Visits: 346
Thanks for the better explanation of the Decimal function, as I was very confused about that one statement!
Intersting question though.
Post #979322
DugyC
DugyC
Posted Thursday, September 02, 2010 2:29 AM
Ten Centuries
Group: General Forum Members
Last Login: Today @ 5:21 AM
Points: 1,162,
Visits: 728
Thanks happycat for the detailed explanation, makes perfect sense now.
_____________________________________________________________________
"The difficult tasks we do immediately, the impossible takes a little longer"
Post #979341
Koen Verbeeck
Koen Verbeeck
Posted Thursday, September 02, 2010 3:53 AM
SSCrazy Eights
Group: General Forum Members
Last Login: Today @ 7:39 AM
Points: 9,370,
Visits: 6,467
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
Daniel Bowlin
Daniel Bowlin
Posted Thursday, September 02, 2010 6:56 AM
SSCrazy
Group: General Forum Members
Last Login: Today @ 8:49 AM
Points: 2,672,
Visits: 2,417
Great follow on explanation. Thanks.
Post #979486
Steve Jones - SSC Editor
Steve Jones - SSC Editor
Posted Thursday, September 02, 2010 9:05 AM
SSC-Dedicated
Group: Administrators
Last Login: Today @ 11:09 AM
Points: 31,416,
Visits: 13,730
Added a bit to the explanation, as per Happycat59
Follow me on Twitter:
@way0utwest
Forum Etiquette: How to post data/code on a forum to get the best help
Post #979625
SQLRNNR
SQLRNNR
Posted Thursday, September 02, 2010 10:17 AM
SSCoach
Group: General Forum Members
Last Login: Yesterday @ 1:07 PM
Points: 18,733,
Visits: 12,332
Thanks for the question.
Jason
AKA CirqueDeSQLeil
I have given a name to my pain...
MCM SQL Server 2008
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 #979685
« Prev Topic
|
Next Topic »
13 posts, Page 1 of 2
1
2
»»
Permissions
You
cannot
post new topics.
You
cannot
post topic replies.
You
cannot
post new polls.
You
cannot
post replies to polls.
You
cannot
edit your own topics.
You
cannot
delete your own topics.
You
cannot
edit other topics.
You
cannot
delete other topics.
You
cannot
edit your own posts.
You
cannot
edit other posts.
You
cannot
delete your own posts.
You
cannot
delete other posts.
You
cannot
post events.
You
cannot
edit your own events.
You
cannot
edit other events.
You
cannot
delete your own events.
You
cannot
delete other events.
You
cannot
send private messages.
You
cannot
send emails.
You
may
read topics.
You
cannot
rate topics.
You
cannot
vote within polls.
You
cannot
upload attachments.
You
may
download attachments.
You
cannot
post HTML code.
You
cannot
edit HTML code.
You
cannot
post IFCode.
You
cannot
post JavaScript.
You
cannot
post EmotIcons.
You
cannot
post or upload images.
Copyright © 2002-2013 Simple Talk Publishing. All Rights Reserved.
Privacy Policy.
Terms of Use.
Report Abuse.