I need to pass set of int to sql procedure.
alter PROC PrCustomerServicesUpd(
@CustomerId UNIQUEIDENTIFIER,
@ServicesIdXml NVARCHAR(1000),
@ServicesIdCount INT =1
)
AS
DECLARE @XmlDocHanle INT
EXEC sp_Xml_PrepareDocument @XmlDocHanle OUTPUT, @ServicesIdXml
SELECT * FROM OPENXML(@XmlDocHanle, '/ROOT/Services/ServicesId',@ServicesIdCount)
WITH (ServiceId INT)
EXEC sp_Xml_RemoveDocument @XmlDocHanle
go
PrCustomerServicesUpd '443c293e-fc78-4562-97f8-ee1f2b54f813'
,'<Services><ServiceId>12</ServiceId><ServiceId>156</ServiceId></Services>',22
This script returns one empty field named ‘ServiceId’ instead of 2 rows.
Assuming this is SQL Server 2000 (otherwise there is no sane reason to use OPENXML), you need to get the
text()within the node, otherwise it tries to find the attribute “ServiceId” within the node “ServiceId”. Also your parameter XML is completely out of sync with what the proc expects.Using the XML data type