I have the following query:
SELECT
Quotes.quoteID, Orders.orderID, Orders.invoiceID,
Quotes.parentOrderID AS QuoteParent, Orders.parentOrderID AS OrderParent
FROM
Quotes
INNER JOIN
Orders ON Quotes.orderID = Orders.orderID
I need to fill all the OrderParent columns with valid (not null) values in QuoteParent column.
How do I write the UPDATE query?
>Solution :
How about:
UPDATE o
SET parentOrderID = q.parentOrderID
FROM dbo.Orders o
INNER JOIN Quotes q ON o.OrdersID = q.OrderID
WHERE o.parentOrderID IS NULL
AND q.parentOrderID IS NOT NULL
