I have an XML being passed into a stored procedure in the following format. I'm struggling with how to shred it in SQL Server 2017:
declare @xml xml = convert(xml, N'<SearchQuery>
<DealTypeDesc>Deal</DealTypeDesc>
<VendorNum>1</VendorNum>
<VendorName>Vendor1</VendorName>
<VendorNum>2</VendorNum>
<VendorName>Vendor2</VendorName>
<VendorNum>3</VendorNum>
<VendorName>Vendor3</VendorName>
<VendorNum>4</VendorNum>
<VendorName>Vendor4</VendorName>
<VendorNum>5</VendorNum>
<VendorName>Vendor5</VendorName>
</SearchQuery>')
-- this is how it is being consumed now. 1 element at a time
SELECT
t.c.value('text()[1]', 'NVARCHAR(MAX)') AS LookupValue
FROM
@xml.nodes('//SearchQuery/VendorNum') AS t(c)
-- I want the results to look like this where I can use the node name as a column and the value as a lookup.
-- I wanted to do this in one pass without having to union all and select from the XML variable every time.
-- I can't change the XML structure since it's coming from a third party, so that option is out.
SELECT
'VendorName' ColumnName,
t.c.value('text()[1]', 'NVARCHAR(MAX)') AS LookupValue
FROM
@xml.nodes('//SearchQuery/VendorName') AS t(c)
UNION ALL
SELECT
'VendorNum' ColumnName,
t.c.value('text()[1]', 'NVARCHAR(MAX)') AS LookupValue
FROM
@xml.nodes('//SearchQuery/VendorNum') AS t(c)

You could query the two columns separately then join as follows: