[英]Is there SQL function to update table by replacing one column with data (DIFFERENT TYPE) from another column (in a related table)?
I run into a problem in SQL, I don't know how to update table A by replacing its column "Edu" with another column "Level" of table B.我在 SQL 中遇到问题,我不知道如何通过将表 A 的列“Edu”替换为表 B 的另一列“级别”来更新表 A。
UPDATE A SET A.Edu= CAST(B.Level AS Varchar(Max)) FROM A INNER JOIN B ON A.Edu=B.Edu; UPDATE A SET A.Edu= CAST(B.Level AS Varchar(Max)) FROM A INNER JOIN B ON A.Edu=B.Edu;
Maybe an idea.也许是一个想法。 I think your query doesnt work because you try to update a key using a the same time this key, A.Edu.我认为您的查询不起作用,因为您尝试使用此密钥 A.Edu 更新密钥。
My solution: create in the table A a column EduBis with same value as Edu.我的解决方案:在表 A 中创建与 Edu 具有相同值的 EduBis 列。
Then update with A.EduBis=B.Edu in you clause in the join.然后在连接中的 you 子句中使用 A.EduBis=B.Edu 进行更新。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.