Im trying to filter XML by joining Element Name to a value in a row.Here is the wrong way:declare @x xmlset @x = '<t> <One>val</One> <Two>val</Two> <Three>val</Three></t>'declare @t table (ElementName varchar(10))insert into @t select 'One' union select 'Three'declare @Return nvarchar(1000)select @Return = coalesce(@Return + '', '') + '<' + cast(c.query('fn:local-name(.)') as nvarchar(500)) + '>' + cast(c.query('./text()') as nvarchar(500)) + '</' + cast(c.query('fn:local-name(.)') as nvarchar(500)) + '>'from @x.nodes(N'//*') x(c)innerjoin @t t on cast(c.query('fn:local-name(.)') as nvarchar(500)) = t.ElementNameselect cast(@Return as xml)for xml path('t'), typeIs there a way to act directly on the XML?Thanks for any help.