Click here to Skip to main content
15,889,335 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,

I have to update two table values at same time. In first table current values will be store. In second table previous values (ie.before edited values) should be store. I can do this for one value only. But i want to update multiple column values in single query. If you have any idea please guide me. I don't know exactly that syntax. I tried this. If any mistake please correct me.

SQL
UPDATE rskpcfceditlog SET
            rskpcfceditlog.pcfcbankref = (SELECT rskpcfc.pcfcbankref FROM rskpcfc WHERE
            rskpcfc.pcfcid = rskpcfceditlog.pcfcid)
            rskpcfceditlog.actype = (SELECT rskpcfc.pcfcbankref,rskpcfc.actype FROM rskpcfc WHERE
            rskpcfc.pcfcid = rskpcfceditlog.pcfcid)
            WHERE EXISTS (SELECT rskpcfc.pcfcbankref,rskpcfc.actype FROM rskpcfc WHERE rskpcfc.pcfcid = rskpcfceditlog.pcfcid and rskpcfceditlog.pcfcid=@cond1);


if i do this for one value it will work. But i have to do multiple columns.


Thanks.
Posted

1 solution

You can try this

SQL
UPDATE  rskpcfceditlog
SET     pcfcbankref = rskpcfc.pcfcbankref,
        actype      = rskpcfc.actype
        --, add more columns here
FROM    rskpcfceditlog
JOIN    rskpcfc
        ON rskpcfc.pcfcid = rskpcfceditlog.pcfcid
WHERE   rskpcfceditlog.pcfcid   = @cond1
 
Share this answer
 
Comments
Jayanthi-SE 12-Feb-12 23:06pm    
Hi,

Thanks a lot, its working

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900