Log in  ::  Register  ::  Not logged in

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

 What will this return? Rate Topic Display Mode Topic Options
Author
 Message
 Posted Wednesday, May 26, 2010 12:57 AM
 SSCertifiable Group: General Forum Members Last Login: Today @ 1:48 PM Points: 7,765, Visits: 11,376
 bkubicek (5/25/2010)Hugo,It is the precision of the variable you are putting the value into that matter. @min is a numeric(10,4), so you will get your four decimal places using plain old 60.0.BenI assume you meant to write that @hourDiff is nummeric(10,4); @min is an integer. If that is what you meant, then you are right that the end result will always be converted to numeric(10,4). But intermediate results use a different precision; the casting to the target data type of numeric(10, 4) is the final step.Run the following code to see how the data types used for the operands of the division affect the length and precision of the intermediate result. In this case, since the division result is exactly 1.5, there will not be any net effect. But there are cases where the number of decimals used in the intermediate result may affect the end result. (Keep in mind that the division result will be truncated to the precision of the intermediate result, which will then be rounded to the precision of the variable).The difference will never be more than 0.0001, which admittedly is not significant in most cases. But in those cases where that difference is important, the difference between "60.0" and "CAST(60 AS numeric(10,4))" does matter. Hugo Kornelis, SQL Server MVPVisit my SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis
Post #927978
 Posted Wednesday, May 26, 2010 12:59 AM
 SSCertifiable Group: General Forum Members Last Login: Today @ 1:48 PM Points: 7,765, Visits: 11,376
 Rajasekhar Reddy (5/26/2010)Hi,select command in the code is used for assginign variables not to print any output.the given code won't return any value.Thanks,RajaSekhar Reddy .KThat is entirely correct. Of course, the question was "what result will @hourdiff hold?", not "what will be returned when you run this code", so I fail to see the significance of this observation. Hugo Kornelis, SQL Server MVPVisit my SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis
Post #927980
 Posted Wednesday, May 26, 2010 12:16 PM
 SSCrazy Eights Group: General Forum Members Last Login: Today @ 6:42 AM Points: 9,932, Visits: 11,347
 What Hugo said. Paul WhiteSQLPerformance.comSQLblog.com@SQL_Kiwi
Post #928515
 Posted Wednesday, May 26, 2010 12:26 PM
 Hall of Fame Group: General Forum Members Last Login: Tuesday, November 29, 2016 2:42 PM Points: 3,370, Visits: 6,889
 I got it wrong. I answered "purple". __________________________________________________Against stupidity the gods themselves contend in vain. -- Friedrich Schiller Stop, children, what's that sound? Everybody look what's going down. -- Stephen Stills
Post #928524
 Posted Wednesday, May 26, 2010 12:29 PM
 SSCrazy Eights Group: General Forum Members Last Login: Today @ 6:42 AM Points: 9,932, Visits: 11,347
 The Dixie Flatline (5/26/2010)I got it wrong. I answered "purple". *sound of a mouthful of tea hitting an LCD screen at high speed* Paul WhiteSQLPerformance.comSQLblog.com@SQL_Kiwi
Post #928532
 Posted Wednesday, May 26, 2010 12:36 PM
 SSC-Insane Group: General Forum Members Last Login: Monday, November 21, 2016 11:03 AM Points: 20,009, Visits: 18,255
 The Dixie Flatline (5/26/2010)I got it wrong. I answered "purple". Family Feud Style:"Good Answer, Good Answer!!" Jason AKA CirqueDeSQLeilI have given a name to my pain...MCM SQL Server, MVPSQL RNNRPosting Performance Based Questions - Gail Shaw
Post #928538
 Posted Wednesday, May 26, 2010 1:08 PM
 Old Hand Group: General Forum Members Last Login: Thursday, June 18, 2015 8:25 AM Points: 300, Visits: 342
 Put select @hourDiff at the end of the code and rerun it.
Post #928566
 Posted Wednesday, May 26, 2010 1:18 PM
 Old Hand Group: General Forum Members Last Login: Thursday, June 18, 2015 8:25 AM Points: 300, Visits: 342
 Put the below statment at the end of the code and rerun it.select @hourDiff
Post #928578
 Posted Thursday, May 27, 2010 4:13 AM
 SSC-Enthusiastic Group: General Forum Members Last Login: Tuesday, February 8, 2011 7:03 AM Points: 125, Visits: 51
 I run solved this query then I answerd NULL, because you forget to write select @hourDiff in your query.so my answer is write NULL. if you wrote select @hourDiff at the last line then it will return 1.
Post #928859
 Posted Thursday, May 27, 2010 4:18 AM
 SSCrazy Eights Group: General Forum Members Last Login: Today @ 6:42 AM Points: 9,932, Visits: 11,347
 Z.A.T (5/27/2010)I run solved this query then I answerd NULL, because you forget to write select @hourDiff in your query.so my answer is write NULL. if you wrote select @hourDiff at the last line then it will return 1.One might argue that the blame lies elsewhere, and the 'crime' committed was not reading the question properly.Attention to detail is often a desirable trait in DBAs...My other thought is that omitting the SELECT statement made it easier to get wrong for those people who just copy the code and execute it. Paul WhiteSQLPerformance.comSQLblog.com@SQL_Kiwi
Post #928862

 Permissions

 Copyright © 2002-2016 Redgate. All Rights Reserved. Privacy Policy. Terms of Use. Report Abuse.