khsaunderson
Technical User
I am trying to update various rows in a specific column of a table in DB2. I am, however, used to MS SQL, so am not sure how I would do this. The SELECT is..
SELECT *
FROM Tbl1
INNER JOIN Tbl2 ON Tbl2.LICCODE = Tbl1.SALLICN
INNER JOIN Tbl3 ON Tbl3.LCULICN = Tbl2.LICCODE
INNER JOIN Tbl4 ON Tbl4.CURCODE = Tbl3.LCUCURR
AND RIGHT(CURDATE,4) = RIGHT(Tbl1.SALPERIOD,4)
WHERE Tbl1.SALEXCH <> Tbl4.CURDETAIL
Normally in MS SQL I would just use the FROM bit of the statement under the UPDATE/SET bit so I could filter out to the correct fields, but DB2 doesn't accept the FROM clause.
UPDATE Tbl1
SET SALEXCH = CURDETAIL
FROM Tbl1
INNER JOIN Tbl2 ON Tbl2.LICCODE = Tbl1.SALLICN
INNER JOIN Tbl3 ON Tbl3.LCULICN = Tbl2.LICCODE
INNER JOIN Tbl4 ON Tbl4.CURCODE = Tbl3.LCUCURR
AND RIGHT(CURDATE,4) = RIGHT(Tbl1.SALPERIOD,4)
WHERE Tbl1.SALEXCH <> Tbl4.CURDETAIL
How else could I do this?
SELECT *
FROM Tbl1
INNER JOIN Tbl2 ON Tbl2.LICCODE = Tbl1.SALLICN
INNER JOIN Tbl3 ON Tbl3.LCULICN = Tbl2.LICCODE
INNER JOIN Tbl4 ON Tbl4.CURCODE = Tbl3.LCUCURR
AND RIGHT(CURDATE,4) = RIGHT(Tbl1.SALPERIOD,4)
WHERE Tbl1.SALEXCH <> Tbl4.CURDETAIL
Normally in MS SQL I would just use the FROM bit of the statement under the UPDATE/SET bit so I could filter out to the correct fields, but DB2 doesn't accept the FROM clause.
UPDATE Tbl1
SET SALEXCH = CURDETAIL
FROM Tbl1
INNER JOIN Tbl2 ON Tbl2.LICCODE = Tbl1.SALLICN
INNER JOIN Tbl3 ON Tbl3.LCULICN = Tbl2.LICCODE
INNER JOIN Tbl4 ON Tbl4.CURCODE = Tbl3.LCUCURR
AND RIGHT(CURDATE,4) = RIGHT(Tbl1.SALPERIOD,4)
WHERE Tbl1.SALEXCH <> Tbl4.CURDETAIL
How else could I do this?