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 2000 Forums
 SQL Server Development (2000)
 Convert in DECIMAL

Author  Topic 

vladimir_grigoro
Yak Posting Veteran

62 Posts

Posted - 2002-02-24 : 02:03:56
I have:

TABLE A
COLUMN: A int
COLUMN: B int
COLUMN: C decimal


I am trying to UPDATE TABLE A COLUMN C AS result from calculation from COLUMN A & B. I mean UPDATE TABLE A SET C=(A/B)*100 I am trying to receive a something as a percentage.

But anytime I receive the result with a round value EXAMPLE: (123/1234)*100=9.97 but I receive in COLUMN C 9.00; I tryed with CAST & CONVERT function but without success. When I changed COLUMN A and B to decimal there is no problem, everything is all right.

However, Could somebody help me with a query to calculate the example above without changing COLUMN data types?

samrat
Yak Posting Veteran

94 Posts

Posted - 2002-02-24 : 03:01:09
Try this out, and see how u go

UPDATE Table1 SET C = (cast(A as decimal)/cast(B as decimal)) *100

Cheers,

Samrat Valani

Edited by - samrat on 02/24/2002 03:02:29
Go to Top of Page

nr
SQLTeam MVY

12543 Posts

Posted - 2002-02-24 : 05:24:45
also
UPDATE Table1 SET C = 100.0 * A / B

should work.



==========================================
Cursors are useful if you don't know sql.
Beer is not cold and it isn't fizzy.
Go to Top of Page
   

- Advertisement -