Sunday, February 26, 2012

Format number

I am doing some simple arithmatic for a query that I am working on. What I have below describes the arithmatic that is taking place withing a portion of the query:

select(o.sales_val/o.qty_sales) as 'Unit_Price', (o.acctng_cost_val/o.qty_sales) as 'Unit_Cost'
from opcsahf as o
go

The division is correct. My only issue is that the results for 'Unit Price' or 'Unit Cost' may be formatted like example: 4.25000000.

How can I have my nubers show up with only to 2 decimal places instead of all the zeros at teh end?It really is a presentation layer issue..

What are the datatypes of the columns

Did you just try CONVERT(decimal(15,2),....|||Brett,

I went ahead and tryed the convert(decimal(15,2) and everything worked fine. This was the results for the statement:

select convert(decimal (15,2),o.sales_val/ convert(decimal (15,2),o.qty_sales)) as 'Unit_Price', convert(decimal (15,2),o.acctng_cost_val/ convert(decimal (15,2),o.qty_sales)) as 'Unit_Cost'
from opcsahf as o
go

Thanks alot Brett. It did the trick.

Originally posted by Brett Kaiser
It really is a presentation layer issue..

What are the datatypes of the columns

Did you just try CONVERT(decimal(15,2),....

No comments:

Post a Comment