SQL Join 2 tables together命令

时间:2015-12-01 09:03:07

标签: c# sql asp.net

enter image description here

我有2个如上所述的表,我想将当前的团队名称传递给Player表的Previous_Club列。我已将登录的Team用户的Team_ID设置为会话变量,因此我尝试使用此查询Teams_Name,然后将其传递给Player到Previous_Club列。但它不断出错。您可以在下面看到sql命令。

SqlCommand cmd2 = new SqlCommand("UPDATE Player SET Previous_Club = Team_Name FROM (SELECT Team_Name FROM TEAM WHERE Team_ID = @Team_ID)", con);

2 个答案:

答案 0 :(得分:1)

试试这个;

SqlCommand cmd2 = new SqlCommand("UPDATE Player SET Previous_Club = (SELECT Team_Name FROM TEAM WHERE Team_ID = @Team_ID)", con);

答案 1 :(得分:1)

查询错误。试试这个

UPDATE Player 
SET Previous_Club = (SELECT Team_Name FROM TEAM WHERE Team_ID = @Team_ID)