Hi am trying to update a table with the emails from another table using ids that match in both tables. I must be doing it wrong because i get these errors
"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"."
Any help would be appreciated.
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
Try this:
Fix your first 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
The variables need switching from
DECLARE @ListOfUserIdsAndEmails TABLE( UserEmail nvarchar(256),IDs uniqueidentifier);
to this
DECLARE @ListOfUserIdsAndEmails TABLE(IDs uniqueidentifier, UserEmail nvarchar(256));
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.