August 26, 2009 at 8:51 pm
Thank you! π
August 26, 2009 at 8:56 pm
Glad I could help.
August 27, 2009 at 10:18 am
One additional comment:
If you are ever working with FLOAT datatypes you can't use the modulo (%) operator. In that case, you can use ROUND with the truncate option to test the result.
declare @a float
declare @b-2 float
set @a = 6
set @b-2 = 3
select @a/@b as [a/b],ROUND(@a/@b,0) as [Round(A/B)],
case when @a/@b = ROUND(@a/@b,0) then 'Expression is a whole number.' else 'Expression is a fraction.' end as [result]
BUT, do NOT use ROUND for integers.
If @a and @b-2 are both integers then @a/@b will also be an integer.
__________________________________________________
Against stupidity the gods themselves contend in vain. -- Friedrich Schiller
Stop, children, what's that sound? Everybody look what's going down. -- Stephen Stills
August 27, 2013 at 12:45 am
looks like a assignment question to me ... Or he is just so happy to get the answer π
August 27, 2013 at 1:52 am
twin.devil (8/27/2013)
looks like a assignment question to me ... Or he is just so happy to get the answer π
Four years on...he's your tutor now.
For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
August 27, 2013 at 2:05 am
Could also use the ISNUMERIC function to check that the data is an integer value.
August 27, 2013 at 12:52 pm
Jason.Reeves (8/27/2013)
Could also use the ISNUMERIC function to check that the data is an integer value.
Be careful, now. Please see the following article for why ISNUMERIC should never be used for an ISInteger or IsAllDigits function. It just wasn't designed for that.
http://www.sqlservercentral.com/articles/IsNumeric/71512/
--Jeff Moden
Change is inevitable... Change for the better is not.
August 27, 2013 at 1:19 pm
Jeff Moden (8/27/2013)
Jason.Reeves (8/27/2013)
Could also use the ISNUMERIC function to check that the data is an integer value.Be careful, now. Please see the following article for why ISNUMERIC should never be used for an ISInteger or IsAllDigits function. It just wasn't designed for that.
Not to mention that ISNUMERIC here just completely missed the point of the post. The OP was trying to determine if @a / @b-2 resulted in an integer. ISNUMERIC has it's shortcomings but has no relevance to this thread. 7/3.0 is not an integer but the result certainly is a number. π
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 β Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
Viewing 10 posts - 1 through 9 (of 9 total)
You must be logged in to reply to this topic. Login to reply