Haldamir
Haldamir

Reputation: 115

SQL Join 2 tables together command

enter image description here

I have 2 tables as outlined above and I want to pass the current teams name into the Previous_Club column of the Player table. I have the logged in Team user's Team_ID set as a session variable so I am trying to query the Teams_Name using this and then passing it across to Player into the Previous_Club column. But it keeps erroring out. You can see the sql command below.

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

Upvotes: 0

Views: 97

Answers (2)

Neeraj Sharma
Neeraj Sharma

Reputation: 588

Try this one;

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

Upvotes: 1

vinayak
vinayak

Reputation: 65

Query Error..Try this one

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

Upvotes: 1

Related Questions