SQL Server beginner here. I am having some trouble on a SELECT/UPDATE statement. I have a table with an order number column and a line number column. The select statement below returns the values I want. I would like to take the result and insert that number into a column on the same table where the order number matches. Am I over thinking this? Or maybe under thinking the complexity? 🙂
SELECT
ORDNUM, COUNT(LINNUM) AS 'CountLines'
FROM [TableName]
WHERE STS = '3' AND DUEQTY < ONHAND AND STYPE = 'CU'
GROUP BY ORDNUM
UPDATE [TableName]
SET LNCNT = 'CountLines'
WHERE ORDNUM = ORDNUM
Thank you in advance.
Ben
UPDATE: I used Andomars solution below and it worked great. Thank you all for the assistance.
Using SQL Server syntax: