Author: Isaac Tonny

Question: Below is the SQL I use to create my pivot table. I need to replace null values with ‘0’, however, I get an error when trying to use a case expression inside the pivot. Is this not possible? SELECT * FROM ( SELECT c.CompanyName, p.ProductName, od.Quantity FROM Customers as c INNER JOIN Orders as o ON c.CustomerID = o.CustomerID INNER JOIN [Order Details] as od ON o.OrderID = od.OrderID INNER JOIN Products as p on od.ProductID = p.ProductID ) as QuantityOrdered pivot ( (CASE WHEN SUM(Quantity) is NULL THEN 0 ELSE SUM(Quantity) END) for ProductName in ([Alice Mutton], [Aniseed…

Read More