我正在尝试从一个SQL查询更新我的Scout
和ScoutRole
表。我试过这个例子:How to update two tables in one statement in SQL Server 2005?。
但我一直收到错误消息
无法绑定多部分标识符“SR.Role”
我该如何解决这个问题?
BEGIN TRANSACTION
UPDATE Scout
SET Scout.FirstName = @ScoutFirstName,
Scout.LastName = @ScoutLastName,
Scout.EmailAddress = @EmailAddress,
Scout.ClubID = @ClubID
FROM Scout S, ScoutRole SR
WHERE S.ScoutID = SR.ScoutID AND S.ScoutID = @ScoutID
UPDATE ScoutRole
SET SR.Role = @ScoutRole,
SR.Username = @Username,
SR.Password = @Password
FROM Scout S, ScoutRole SR
WHERE S.ScoutID = SR.ScoutID AND S.ScoutID = @ScoutID
COMMIT
答案 0 :(得分:1)
这应该是您需要使用的全部内容:
BEGIN TRANSACTION
UPDATE Scout
SET FirstName = @ScoutFirstName,
LastName = @ScoutLastName,
EmailAddress = @EmailAddress,
ClubID = @ClubID
WHERE ScoutID = @ScoutID
UPDATE ScoutRole
SET Role = @ScoutRole,
Username = @Username,
Password = @Password
WHERE ScoutID = @ScoutID
COMMIT