请问,IN 运算符可以这么用吗?
CREATE PROC up_myp
@IDS nvarchar(2000)
AS
SELECT * FROM UserInfo WHERE UserID in (@IDS)
go
---------------------------
up_myp '1,2 '
/*
服务器: 消息 245,级别 16,状态 1,过程 up_myp,行 4
将 nvarchar 值 '1,2 ' 转换为数据类型为 int 的列时发生语法错误。
*/
------解决方案--------------------CREATE PROC up_myp
@IDS nvarchar(2000)
AS
exec ( 'SELECT * FROM UserInfo WHERE UserID in ( '+@IDS+ ') ')
go
------解决方案--------------------UserID为数值型.
SELECT * FROM UserInfo WHERE UserID in (@IDS)
UserID为字符型.
declare @sql as varchar(100)
set @sql = 'SELECT * FROM UserInfo WHERE UserID in ( ' ' ' + @IDS + ' ' ') '
exec(@sql)