>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 >END >>
>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.PKValue >>