April 26, 2011 at 12:16 pm
Removed by GaMusicMan
April 26, 2011 at 12:21 pm
You are asking for an integer result by dividing and INT by an INT.
Try forcing a conversion to numeric during the calculation by adding a decimal to one of the numbers.
Print (5596. / 11784)
______________________________________________________________________
Personal Motto: Why push the envelope when you can just open it?
If you follow the direction given HERE[/url] you'll likely increase the number and quality of responses you get to your question.
Jason L. SelburgApril 26, 2011 at 12:23 pm
GaMusicMan (4/26/2011)
In the SQL Server 2005 Management Studio, I have the following line of code in the query:Print (5596 / 11784)
This should return the decimal .47 . Instead it returns 0.
Can anyone tell me why this expression returns 0 instead of .47 . I'd appreciate your feedback. I'M STUCK HERE.
Dividing an integer by an integer yields an integer result. Try casting an operand into your required datatype:
SELECT CAST(5596 AS NUMERIC(6,2))/ 11784
SELECT 5596/CAST(11784 AS NUMERIC(7,2))
For better assistance in answering your questions, please read this[/url].
Hidden RBAR: Triangular Joins[/url] / The "Numbers" or "Tally" Table: What it is and how it replaces a loop[/url] Jeff Moden[/url]
April 26, 2011 at 12:24 pm
That works. Thank you.
April 26, 2011 at 12:24 pm
Because that an INTEGER division; Interger division will round off the result to the nearest lower integer. Try this instead
Print (5596.00 / 11784.00)
April 26, 2011 at 12:25 pm
Both of your suggestions worked. thanks a lot. I'm getting the hang of this T-SQL thing.... little by little...
April 26, 2011 at 12:25 pm
😀 3 replies 🙂 with the same answer 😉
Viewing 7 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply