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 ENDThis will allow you to pass any XML string and receive a table variable in return.
DECLARE @XMLString XML SET @XMLString ='<Customers> <Customer> <PKValue>2</PKValue> <PKValue>5</PKValue> </Customer> </Customers>' -- Perform a JOIN using the UDF SELECT Customers.* FROM Customers JOIN [dbo].[XML2TableVar] (@XMLString) CustList ON Customers.CustomerPK = CustList.PKValueSo there it is...you just call the UDF in your SELECT statement, and it returns a table variable that you can use in a JOIN.