January 26, 2005 at 12:16 pm
I have a view that selects COUNT outputs from two other views. I want to find the percentage of between both columns but when I divide the the percentage isn't acurate for some (i.e. 7/121). Well I tried to cast the all the columns in the view but that doesn't work either. Here is what I did:
select
cast ((NoteCount) as decimal) as NoteCount,cast ((OrderCount) as decimal) as OrderCount,cast (((NoteCount/OrderCount)*100) as decimal (10,5))as Percentage,o.First_Name,o.Last_Name
from v_MTSTM_ORDERCOUNT o JOIN v_MTSTM_NOTECOUNT n ON o.last_name = n.last_name
So I was thinking if I CAST the COUNT Columns from the first two views then maybe it will work. Not Sure. Any ideas???? Thanks!
January 26, 2005 at 12:28 pm
Look carefully at this:
cast (((NoteCount/OrderCount)*100) as decimal (10,5))as Percentage
You are casting the result of the calculation, not the pre-computed values. Any truncation is happening before you've done your cast.
January 26, 2005 at 12:34 pm
try this :
NoteCount/OrderCount * 1.0
January 26, 2005 at 1:10 pm
Thanks Remi that worked well. I also tried this and it worked:
select
NoteCount,OrderCount,convert (decimal (8,2),((NoteCount/OrderCount)*100)) as Percentage,o.First_Name,o.Last_Name
from v_MTSTM_ORDERCOUNT o JOIN v_MTSTM_NOTECOUNT n ON o.last_name = n.last_name
I'll have to practice with CONVERT some more. Thanks again!
Viewing 4 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy