declare @orderType Nvarchar(20)
set @orderType = '0,1'
Select * from Orders where OrderType In (@orderType) Order By Id Desc其中OrderType列的类型为Int运行提示错误:
服务器: 消息 245,级别 16,状态 1,行 3
将 nvarchar 值 '0,1' 转换为数据类型为 int 的列时发生语法错误。想请教一下有什么处理办法?

解决方案 »

  1.   

    declare @orderType Nvarchar(20)
    declare @sql varchar(800)
    set @orderType = '0,1'
    set @sql='Select * from Orders where OrderType In (' + @orderType + ) Order By Id Desc'
    exec(@sql)
      

  2.   

    declare @orderType Nvarchar(20)
    set @orderType = '0,1'
    Exec('Select * from Orders where OrderType In ('+@orderType+') Order By Id Desc ')