Solved

# Compute average without rounding

Posted on 2006-05-24
273 Views
I am trying to get the average number of items for all orders. With two decimal places.

SELECT CONVERT(DECIMAL(10,2),AVG(Items/Orders)) AvgItems
FROM table

I should get 2.77 as the result of dividing 333905 items by 120402 orders. I get 2.00.
I have tried SUM and AVG. What am I doing wrong?
0
Question by:Laura2112

LVL 142

Accepted Solution

SELECT CONVERT(DECIMAL(10,2),AVG(cast(Items as decimal(10,2))/cast(Orders as decimal(10,2)) )) AvgItems
FROM table
0

Author Comment

Right on!  Thanks!
0

LVL 34

Expert Comment

You actually only need to cast one of them

SELECT AVG(Items/CAST(Orders AS decimal(10,2)) AvgItems
FROM table
0

## Featured Post

### Suggested Solutions

Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.