关于SQL语句中使用变量的问题!

wangsy80 2006-03-16 12:30:05
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 的列时发生语法错误。

想请教一下有什么处理办法?
...全文
87 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
wangsy80 2006-03-16
  • 打赏
  • 举报
回复
多谢!
zlp321002 2006-03-16
  • 打赏
  • 举报
回复
declare @orderType Nvarchar(20)
set @orderType = '0,1'
Exec('Select * from Orders where OrderType In ('+@orderType+') Order By Id Desc ')
云中客 2006-03-16
  • 打赏
  • 举报
回复
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)

34,594

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧