Sqlserver in 句语实现参数化查询 XML类型解决方案

作者:袖梨 2022-06-29

1:如果参数是int类型:

 代码如下 复制代码

declare @a xml
set @a='
1
5
4
3
2'
select * from product where id in (
select d.x.value('./id[1]','int') from @a.nodes('/*') as d(x))

 

1:如果参数是varchar类型:

 代码如下 复制代码

declare @a xml
set @a='
a
b5
c4
d3
e2'
select * from product where pname in (
select d.x.value('./name[1]','varchar(100)') from @a.nodes('/*') as d(x))

相关文章

精彩推荐