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
 Transact-SQL (2000)
 Convert a calculated numeric value to 2 decimal

Author  Topic 

zeeshan13
Constraint Violating Yak Guru

347 Posts

Posted - 2007-08-02 : 11:48:36

Hi All,

I have a table called Table1. It has the following 2 fields and datatypes.

scn_dol_am (decimal with precision 18 & scale 2)
scn_unt_qy (BigInt)

I am running the following simple select statement.

select (scn_dol_am/scn_unt_qy) Price from Table1

Note that I am dividing the 2 fields and getting the result in the following format (following are some examples).

1.0500000000000000000000
1.3400000000000000000000
1.3333333333333333333333
1.8500000000000000000000
3.4900000000000000000000

I want the above to be displayed as decimal with a scale of 2. Meaning I want it to be display as decimal rounded to 2 decimal place.

How can I achieve this?.

Thanks a million....

Zee







SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-08-02 : 11:55:41
select price, round(scn_dol_am/scn_unt_qy, 2), cast(scn_dol_am/scn_unt_qy as decimal(18,2))
from Table1



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

sshelper
Posting Yak Master

216 Posts

Posted - 2007-08-02 : 11:56:27
Try CASTing the result to DECIMAL as follows:

select CAST(scn_dol_am/scn_unt_qy AS DECIMAL(18, 2)) Price from Table1

SQL Server Helper
http://www.sql-server-helper.com
Go to Top of Page
   

- Advertisement -