Here’s my setup: I am passing two arrays as XML into a SQL stored procedure.
These are:
<PhoneID Value=128/>
<PhoneID Value=129/>
<PhoneID Value=130/>
and
<AddressID Value=268/>
<AddressID Value=157/>
<AddressID Value=395/>
The Address and Phone tables look like this (pseudo-code follows):
Phone:
BIGINT PhoneID
BIGINT PhoneNumber
SMALLINT AreaCode
INT Extension
Address:
BIGINT AddressID
NVARCHAR StreetAddress
NVARCHAR CountryName
NVARCHAR City
BIGINT Zip
My dilemma is this:
I need to walk through the passed in arrays in lock-step to return
ContactInfo:
BIGINT PhoneNumber
NVARCHAR StreetAddress
BIGINT ZipCode
i.e. I need to return one ContactInfo built from Phone where PhoneID = 128 and Address where AddressID = 268, and another where PhoneID = 129 and AddressID = 268, etc.
My big question is: How do I walk two xml arrays in lock-step in sql?
This is in SQL Server 2008 R2.
Thanks everyone 🙂
Turns out it’s possible to in T-SQL, like so:
However, intrinsic knowledge of the XML is required.
The above implies the XML schema:
where both, ‘XmlArgs’ and ‘Value’ are case sensitive.