一条简单的查询就这么难

jdzwhy 2009-03-04 11:31:42
declare @strid varchar(20)

set @strid='57,4,61'

selct * from temp where convert(varchar,id) in (57,4,61)--可以查到记录

selct * from temp where convert(varchar,id) in (@strid)--通过参数传递为什么却查询不到记录
...全文
71 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
sdhdy 2009-03-04
  • 打赏
  • 举报
回复
declare @strid varchar(20) 
set @strid='57,4,61'
exec ('select * from temp where convert(varchar,id) in ('+ @strid +')')
快乐_石头 2009-03-04
  • 打赏
  • 举报
回复
select * from temp where charindex(','+ltrim(id)+',',','+@strid+',')>0
快乐_石头 2009-03-04
  • 打赏
  • 举报
回复
selct * from temp where charindex(','+ltrim(id)+',',','+@strid+',')>0

22,207

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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