sqlserver里如何传递 in参数

 

select *

from table1

where usercode in(@Usercodes) 

传入的参数@Usercodes =  ’code1‘,’code02‘

 

这样是不行的。SQL不支持者样做。

(1)通过拼接 SQL 最后去 exec (@sql)来实现: ’。。。where usercode in('+@Usercodes+') '

(2)通过: select * from table1 where charindex(','+rtrim(usercode )+',' , ','+ @Usercodes +',')>0 来实现。这里

@userCode = code1,code2 (没有用单引号包括起来)

 

 

 

 

 

相关文章:

  • 2021-05-28
  • 2021-11-16
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-18
猜你喜欢
  • 2021-07-08
  • 2021-11-10
  • 2022-12-23
  • 2021-08-14
  • 2022-01-12
  • 2021-07-25
相关资源
相似解决方案