I have a table that I would like to update based on the results of a query. The table that I want updated is called dbo.CSL. The field I want to update is called dbo.CSL.PartType. How can I update this field based on the results of this query?
SELECT
b.Part,
b.PartCreated,
b.LastSalesDate,
CASE WHEN b.LastSalesDate < (getdate()-365) OR b.LastSalesDate IS NULL AND b.PartCreated <= '2013-12-31' THEN 'C'
WHEN b.LastSalesDate < (getdate()-365) OR b.LastSalesDate IS NULL AND b.PartCreated >= '2014-01-01' THEN 'N'
ELSE 'D'
END AS PartType
FROM
(SELECT
a.Part,
a.PartCreated,
MAX(s.SBINDT) AS LastSalesDate
FROM
dbo.SalesData s
RIGHT JOIN
(SELECT
c.Part,
c.PartCreated
FROM
dbo.NewCSL c
) AS a
ON a.Part = s.SBITEM AND s.SBTYPE = 'O'
GROUP BY
a.Part,
a.PartCreated
) AS b
ORDER BY
LastSalesDate