SQL传递参数
declare @SqlWhereProject NVARCHAR(500)
set @SqlWhereProject='and ( FProjectNumber like ''%02.C13001%'')'
select * from t_Item_3001 where 1=1 &@SqlWhereProject
执行以上语句时,提示"在将 nvarchar 值 'and ( FProjectNumber like '%02.C13001%')' 转换成数据类型 int 时失败"
[解决办法]
declare @SqlWhereProject NVARCHAR(500),@sql nvarchar(4000)
set @SqlWhereProject='and ( FProjectNumber like ''%02.C13001%'')'
set @sql='select * from t_Item_3001 where 1=1 '+ @SqlWhereProject
exec(@sql)