SQL How to update a column from the same table base in a text reference?

Viewed 43

I need to update the order number of the actuals table's rows. The rows that need to be updated are identified through having their text column end with the invoice number. In the same table can be found the invoice lines that are filled with their respective order number. I wrote the following query but it doesn't work all the time. Any idea on what might the issue be?

UPDATE Actuals
SET actuals.[Order no] = newpotable.originalpo
FROM actuals
INNER JOIN 
    (SELECT x.*,POtable.[Order no] AS originalpo
     FROM actuals AS x
     LEFT JOIN 
         (SELECT * FROM actuals WHERE [Order no] IS NOT NULL) AS POtable ON (x.[Long Description] LIKE '%' + POtable.[Invoice Number] + '%')
     WHERE x.[Long Description] LIKE '%tax accrual for%') AS newpotable ON actuals.id = newpotable.id
WHERE
    actuals.[Order no] = '#' 
    AND actuals.[Long Description] LIKE '%tax accrual for%'
0 Answers
Related