如何使用合并更新语句? [英] How do I use the merge update statement?

查看:86
本文介绍了如何使用合并更新语句?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经将sql语句转换为我认为在vb.net中可用的字符串格式。



这是字符串出来的

使用[table2]将[table1]合并为T,在t.first_name = S.first_name上为S,匹配时为T.age = s.age,然后更新Set T.last_name = S.Last_name; 





当我去检查表1中没有任何变化的数据时,如果我遗漏了某些内容或者某些内容,有人可以根据字符串告诉我错误的地方?



我的尝试:



没有数据正被插入到姓氏列中,它保持空白。我已从列名中删除了括号并添加了逗号,但无济于事,我在更新的last_name列中仍然没有得到任何内容。

解决方案

查询看起来很好,检查表中的条件是否匹配,您可以使用联接来查找



 SELECT * FROM Table_1,Table_2 
WHERE Table_1.first_name = Table_2.first_name和Table_1.age = Table_2.age


 MERGE [Table1] T 
使用[table2] S
ON t.first_name = S.first_name和T.age = s.age
WHEN MATCHED THEN UPDATE SET T.last_name = S.Last_name


I have turned the sql statement into what I thought was a usable string format in vb.net.

Here is what the string comes out to be

Merge into [Table1] as T using [table2] as S on t.first_name = S.first_name and T.age = s.age when matched then update Set T.last_name = S.Last_name;



when I go to check the data nothing changes in table 1, could someone tell me based upon the string if I am missing something or if something is in the wrong place?

What I have tried:

No data is being inserted into the last name column it is staying blank. I have removed the brackets from the column names and added commas, but to no avail, I am still getting nothing in the last_name column updated.

解决方案

Query looks fine, Check whether the condition matches in both the table, you can use a join for finding out that

SELECT * FROM Table_1, Table_2 
WHERE Table_1.first_name = Table_2.first_name and  Table_1.age = Table_2.age


MERGE [Table1] T 
USING  [table2] S
ON t.first_name = S.first_name and T.age = s.age
WHEN MATCHED THEN UPDATE SET T.last_name = S.Last_name


这篇关于如何使用合并更新语句?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆