SQLUSA

Microsoft SQL Server 2000 Best Practices

 

How to apply nested CONVERTs for complex data conversion?

 

The following sample script demonstrates the use of nested CONVERTs to convert the result column into currency format:

USE Northwind

SELECT ProductName,
AveragePrice = '$'+CONVERT(varchar, CONVERT(money,AVG(od.UnitPrice*(1.00-Discount)),1)),
UnitsSold = SUM(od.Quantity)
FROM dbo.[Order Details] AS od, dbo.Products AS p, dbo.Orders AS o
WHERE od.ProductID = p.ProductID and o.OrderID = od.OrderID
AND od.UnitPrice > 8.0
GROUP BY ProductName, od.ProductID
ORDER BY ProductName

 

American Standard in SQL Server Training
 
SQLUSA.com Home Page