Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 conversion issue

Author  Topic 

michaelxvo
Starting Member

47 Posts

Posted - 2007-03-09 : 13:23:26
I have a table a
TABLE A
total_count SMALLINT,
total_success SMALLINT,
success_ratio DECIMAL(9,7)

when I use this query
UPDATE TABLE A
SET success_ratio = total_success / total_count

then I issue this query "SELECT * FROM A"
what I see is either 1.0000 or 0.0000 in the success_ratio column
I am suppose to see something like 0.6666 or 0.33333

How can I convert two smallint to make a decimal result

jen
Master Smack Fu Yak Hacker

4110 Posts

Posted - 2007-03-09 : 13:32:28
convert to decimal, also, watch out for the division by zero error and null values

convert(decimal(18,4),total_success)/convert(decimal(18,4),total_count)

HTH

--------------------
keeping it simple...
Go to Top of Page

michaelxvo
Starting Member

47 Posts

Posted - 2007-03-09 : 13:41:01
quote:

convert(decimal(18,4),total_success)/convert(decimal(18,4),total_count)




I got it working

thank you
Go to Top of Page
   

- Advertisement -