exec sp_executesql N'SELECT *编辑得过,查不出结果
FROM VWorkFlowNodes
WHERE (NodeSerils in(@1))',N'@1 nvarchar(4000)',
@1=N'2,5'
exec sp_executesql N'SELECT *正常查询
FROM VWorkFlowNodes
WHERE (NodeSerils in(2,5))'
exec sp_executesql N'SELECT *正常查询
FROM VWorkFlowNodes
WHERE (NodeSerils in(@1))',N'@1 nvarchar(4000)',
@1=N'2'
求解决办法
------解决方案--------------------
之所以有问题,是因为:
exec sp_executesql N'SELECT *
FROM VWorkFlowNodes
WHERE (NodeSerils in(@1))',N'@1 nvarchar(4000)',
@1=N'2,5'
这个语句相当于:
declare @t nvarchar(4000)
set @t = N'2,5'
SELECT *
FROM VWorkFlowNodes
WHERE (NodeSerils in(@1))
这样虽然不报错,但是相当于:
SELECT *
FROM VWorkFlowNodes
WHERE NodeSerils =N'2,5'
所以查询不出结果
------解决方案--------------------
SELECT * FROM VWorkFlowNodes WHERE charindex(','+NodeSerils+',',',2,5,')>0这样呢?有结果不?