当前位置:数据库 > SQLServer >>

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

1:如果参数是int类型:

 代码如下 复制代码

declare @a xml
set @a='
<row><id>1</id></row>
<row><id>5</id></row>
<row><id>4</id></row>
<row><id>3</id></row>
<row><id>2</id></row>'
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='
<row><name>a</name></row>
<row><name>b5</name></row>
<row><name>c4</name></row>
<row><name>d3</name></row>
<row><name>e2</name></row>'
select * from product where pname in (
select d.x.value('./name[1]','varchar(100)') from @a.nodes('/*') as d(x))

补充:数据库,Mssql
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,