我正在尝试执行以下动态查询,但出现错误:Invalid column name 'cat'
DECLARE @SQLDelQuery AS NVARCHAR(1200)
DECLARE @MemberNames varchar(50)
SET @MemberNames = 'cat'
SET @SQLDelQuery = 'SELECT [Email] FROM [aspnet_Membership] am
INNER JOIN [aspnet_Users] u
ON (am.UserId = u.UserId)
INNER JOIN [Member] m
ON (am.UserId = m.UserId)
WHERE u.UserName IN (' + @MemberNames + ')
EXECUTE(@SQLDelQuery)
如果我将其更改为正常查询,我很好:
SELECT [Email] FROM [aspnet_Membership] am
INNER JOIN [aspnet_Users] u
ON (am.UserId = u.UserId)
INNER JOIN [Member] m
ON (am.UserId = m.UserId)
WHERE u.UserName IN ('cat')
谁能指出我的错误?谢谢。