此SQL运行不能通过,为什么?

feburary 2003-11-26 08:58:40
此SQL运行不能通过,为什么?
如果把in换成=则可以通过,为什么?

Declare @temp varchar(100)

select @temp='temp1'

select count(*) from table_name
where (field_name in @temp)
...全文
25 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
gmlxf 2003-11-26
  • 打赏
  • 举报
回复
Declare @temp varchar(100),@sql varchar(200)

select @temp='''temp1'',''temp2'''
set @sql='select count(*) from table_name where (field_name in (' + @temp + '))'

exec (@sql)
welyngj 2003-11-26
  • 打赏
  • 举报
回复
Declare @temp varchar(100)

select @temp='temp1'

exec('select count(*) from table_name
where (field_name in '+@temp)
pengdali 2003-11-26
  • 打赏
  • 举报
回复
Declare @temp varchar(100)

select @temp='''temp1'',''temp2'''

exec('select count(*) from table_name where field_name in ('+@temp+')')
pengdali 2003-11-26
  • 打赏
  • 举报
回复
Declare @temp varchar(100)

select @temp='temp1'

select count(*) from table_name
where field_name in (@temp)

34,623

社区成员

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

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