Question : T SQL Update table.col based on several criteria

I have a query that selects records from orderline table where the flagfield = 'L' and provides the commenttext from the ordercomment table for the same line item.
I want to update a field in the orderline table and set it to the commenttext1 value in the ordercomment table with several criteria in place:  the ordernumber in the line and comment table are equal; the orderlinesequence numbers in the line and comment table are equal; the orderline flagfield = 'L' and the ordercomment commenttext1 value is not null.
Attaching select statement that returns intersection of the records ...
MANY MANY THANKS IN ADVANCE!

Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
--select statement that returns the intersection of the
--records and the values from each table
SELECT      A.SOPNUMBE, A.LNITMSEQ, A.ITEMNMBR, B.SOPNUMBE, B.LNITMSEQ, B.COMMENT_1 
FROM        SOP10200 A
LEFT        OUTER JOIN SOP10202 B ON A.SOPNUMBE = B.SOPNUMBE AND A.LNITMSEQ = B.LNITMSEQ 
WHERE       A.SOPNUMBE = '2050092' AND
            A.COMMNTID  = 'L' AND 
            B.COMMENT_1 IS NOT NULL

Answer : T SQL Update table.col based on several criteria

If I understood well what you want you have to use and UPDATE query with a join.

Try this:
UPDATE SOP10200
SET SOP10200.FieldName = SOP10202.COMMENT_1
FROM SOP10200 INNER JOIN SOP10202 ON SOP10200.SOPNUMBE = SOP10202.SOPNUMBE AND SOP10200.LNITMSEQ = SOP10202.LNITMSEQ
WHERE SOP10200.COMMNTID  = 'L' AND SOP10202.COMMENT_1 IS NOT NULL

Bye.
Random Solutions  
 
programming4us programming4us