我有以下XML
<?xml version="1.0"?>
<ArrayOfInt xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="id">
<int>984026</int>
<int>1005222</int>
</ArrayOfInt>
我将它传递给带有XML参数的存储过程。
我想从xml doc
返回id在int节点中的所有行 SELECT * FROM
MyTable
WHERE
MyTable.Id IN @XMLDoc.value('(.)[1]', 'int')
这只适用于我在xml中发送一个int
<?xml version="1.0"?>
<ArrayOfInt xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="id">
<int>984026</int>
</ArrayOfInt>
但是如果我用两个int节点运行它,sql连接节点
The conversion of the nvarchar value '9840261005222' overflowed an int column.
答案 0 :(得分:1)
declare @XMLDoc xml = '<?xml version="1.0"?>
<ArrayOfInt xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="id">
<int>984026</int>
<int>1005222</int>
</ArrayOfInt>'
;WITH XMLNAMESPACES ('http://www.w3.org/2001/XMLSchema-instance' as xsi ,
'id' as ns2,
DEFAULT 'id')
SELECT MT.*
FROM MyTable
join @XMLDoc.nodes('/ArrayOfInt/int') T(z)
on MT.ID = T.z.value('.','int')