, . , . , SQL .
, XML. , XML, XML. , XML :
<a>
<b>1</b>
<b>3</b>
<b>7</b>
<b>14</b>
<b>147</b>
</a>
( "a" "b" ), SQL-. "b" :
declare @x xml
set @x = '<a><b>1</b><b>3</b><b>7</b><b>14</b><b>147</b></a>'
select t.item.value('.', 'int') from @x.nodes('//a/b') as t(item)
, XML , . , . XML, , :
select * from MyTable where ID in
(select t.item.value('.', 'int') from @x.nodes('//a/b') as t(item))
;with cte as
(select ID = t.item.value('.', 'int') from @x.nodes('//a/b') as t(item))
select * from MyTable inner join cte on MyTable.ID = cte.ID
, , . , JOIN . , XML :
create procedure MyProc @x xml as
begin
set nocount on
;with cte as
(select ID = t.item.value('.', 'int') from @x.nodes('//a/b') as t(item))
select * from MyTable inner join cte on Table.ID = cte.ID
end
:
exec MyProc '<a><b>1</b><b>3</b><b>7</b><b>14</b><b>147</b></a>'
, XML- . XML , , SQL, XML. :
create xml schema collection MyInputSchema as
'<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name="a">
<xsd:complexType>
<xsd:complexContent>
<xsd:restriction base="xsd:anyType">
<xsd:sequence>
<xsd:element name="b" type="xsd:integer" maxOccurs="unbounded" />
</xsd:sequence>
</xsd:restriction>
</xsd:complexContent>
</xsd:complexType>
</xsd:element>
</xsd:schema>'
:
create procedure MyProc @x xml(MyInputSchema) as
begin
set nocount on
;with cte as
(select ID = t.item.value('.', 'int') from @x.nodes('//a/b') as t(item))
select * from MyTable inner join cte on Table.ID = cte.ID
end
XML- 43016 SQL- . 1000 10 10 000 . 72 . , .
. SQL 2005 2008 .