December 12, 2011 at 10:33 pm
Why is my decimal returning 6 in the scale andnot 4 like I need it?
USE TSQLFundamentals2008;
SELECT AVG (LineItems)AS AvgLineItems FROM
(SELECT orderid, CAST (COUNT (productid)AS DECIMAL (8,4))
AS LineItems
FROM Sales.OrderDetails
GROUP BY orderid)AS AvgCount
December 12, 2011 at 11:03 pm
Becuase it is returned by AVG function (SELECT AVG (LineItems)AS AvgLineItems).
Use CAST in the outer SELECT.
December 13, 2011 at 12:22 am
I don't understand please show me what you mean
December 13, 2011 at 12:50 am
USE TSQLFundamentals2008;
SELECT CAST (AVG (LineItems)AS DECIMAL (8,4))
AS AvgLineItems FROM
(SELECT orderid, CAST (COUNT (productid)AS DECIMAL (8,4))
AS LineItems
FROM Sales.OrderDetails
GROUP BY orderid)AS AvgCount
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply