Iterate over the ProductIds. You can fetch the customer from two levels up (../../CustomerId
):
SELECT Finaldata.R.value('(../../CustomerId)[1]','int') as CustomerId
, Finaldata.R.value('(.)[1]','int') as ProductId
FROM @BathData.nodes('/Batch/Customers/Customer/Product/ProductId')
as Finaldata (R)
Dot .
works as a reference to the current node.