CREATE FUNCTION [dbo].[XML2TableVar] ( @XMLString XML) RETURNS @tPKList TABLE ( PKValue int) AS BEGIN INSERT INTO @tPKList SELECT Tbl.Col.value('.','int') FROM @XMLString.nodes('//PKValue') Tbl( Col ) RETURN ENDAnd then use it like this:
DECLARE @XMLString XML SET @XMLString ='<Customers> <Customer> <PKValue>2</PKValue> <PKValue>5</PKValue> </Customer> </Customers>' -- Show the contents SELECT * FROM [dbo].[XML2TableVar] (@XMLString) CustList -- Perform a JOIN using the UDF SELECT Customers.* FROM Customers JOIN [dbo].[XML2TableVar] (@XMLString) CustList ON Customers.CustomerPK = CustList.PKValueObviously, you'd need to modify this to support character columns, but you get the idea...