您正在尝试使用两个表中匹配的ID来更新包含来自另一个表的电子邮件的表。我一定做错了因为我得到了这些错误
"Msg 156, Level 15, State 1, Line 10
Incorrect syntax near the keyword 'IN'.
Msg 1087, Level 15, State 2, Line 10
Must declare the table variable "@ListofPropIDs".
Msg 1087, Level 15, State 2, Line 11
Must declare the table variable "@ListofPropIDs"."
任何帮助都将不胜感激。
DECLARE @ListOfUserIdsAndEmails TABLE(UserEmail VARCHAR(100),IDs VARCHAR(100));
INSERT INTO @ListOfUserIdsAndEmails
SELECT UserId, Username
FROM aspnet_Users
UPDATE UserDetails
SET UserEmail = IN ( SELECT UserEmail from @ListofPropIDs)
WHERE UserIdn = IN ( SELECT IDs from @ListofPropIDs)
GO
答案 0 :(得分:1)
试试这个:
修复您的第一个INSERT:
INSERT INTO @ListOfUserIdsAndEmails
SELECT Username, UserId
FROM aspnet_Users
UPDATE UD
SET UserEmail = P.UserEmail
FROM UserDetails AS UD
JOIN @ListOfUserIdsAndEmailsAS P
ON P.IDs = UD.USerIdn
答案 1 :(得分:0)
变量需要切换 从
DECLARE @ListOfUserIdsAndEmails TABLE( UserEmail nvarchar(256),IDs uniqueidentifier);
到这个
DECLARE @ListOfUserIdsAndEmails TABLE(IDs uniqueidentifier, UserEmail nvarchar(256));