如果一列与其他列表匹配,则更新表的列 [英] Update a columns of table based if one column matches to other columns table

查看:75
本文介绍了如果一列与其他列表匹配,则更新表的列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有学生的表格,其中有我想要更新的字段爱好ID
我还有另一张爱好的表格,其中包含字段姓名和身份



我想做的是

匹配表学生的描述,如果匹配则表爱好名称然后更新HobbiesId表的兴趣爱好这就是我所做的事情

 更新学生设置 HobbiesId =( CASE  
WHEN 描述 like 选择名称来自 [爱好]) THEN - 业余爱好
END



也可以像它一样变得多于列,但我需要一个匹配最多的列

解决方案

试试这个



 更新 Stu 设置 HobbiesId = b.HobbieID 来自学生Stu 加入 [爱好] b 
开启 charindex(b.Name,Stu.Description)> 0


试试这个.............你肯定会得到你的解决方案..



 更新学生 set  student.HobbiesId = Hobbies.HobbiesId  From  student  inner   join 爱好  student.HobbiesId = Hobbies.HobbiesId 









注意:如果这个解决你的问题请点击接受答复。







谢谢

AARIF SHAIKH


你的问题不清楚,我希望你能找到这个



语法:

< pre lang =SQL> 更新 a set a.id = b.id 来自 table1 as inner join table2 as b on a.description = b.name


I Have a table for Student which has field hobbiesId which I want to Update
and I have another table for Hobbies which has field name and id

what i want to do is
match description of table student with name of table hobbies if it matches then update HobbiesId by Id of table Hobbies this is what I have done

Update Student Set HobbiesId=(CASE 
                                 WHEN Description like (Select Name From [Hobbies])                            THEN-- Id of Hobbies
END)


Also in like it may returns more than column but I Need one column which is matching most

解决方案

Try this

Update Stu Set HobbiesId=b.HobbieID from Student Stu Join [Hobbies] b
On charindex(b.Name,Stu.Description)>0


Try This............. Defiantly you will get your Solution..

Update student set student.HobbiesId=Hobbies.HobbiesId From student inner join Hobbies  on student.HobbiesId=Hobbies.HobbiesId





Note: If this Solve your Problem Please click on Accept Answer.



Thanks
AARIF SHAIKH


you Question not Clear, i hope your looking for this

Syntax :

Update a set a.id=b.id From table1 as inner join table2 as b on a.description=b.name


这篇关于如果一列与其他列表匹配,则更新表的列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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