如何将具有值的一个表中的多列更新到另一表中 [英] How to update multiple columns from one table with values to another table
本文介绍了如何将具有值的一个表中的多列更新到另一表中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我必须同时更新两个表值.在第一个表中,将存储当前值.在第二个表中,应存储先前的值(即,在编辑值之前).我只能为一个值执行此操作.但是我想在单个查询中更新多个列的值.如果您有任何想法,请指导我.我不确切地知道那种语法.我试过了如果有任何错误,请纠正我.
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.
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.
推荐答案
您可以尝试一下
You can try this
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
这篇关于如何将具有值的一个表中的多列更新到另一表中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文