simonchristieis
Programmer
I am trying to assign the output of a for xml explicit statement to an xml variable, but I get an error:
I have tried:
And:
Can anyone help point me in the right direction ?
Thanks in advance.
Code:
The FOR XML clause is invalid in views, inline functions, derived tables, and subqueries when they contain a set operator. To work around, wrap the SELECT containing a set operator using derived table syntax and apply FOR XML on top of it.
I have tried:
Code:
DECLARE @outputXML as xml
set @outputXML = (select Tag,Parent,[Level2!1],[Level3!2] from
(
Select 1 as Tag,
null as Parent,
null as [Level2!1],
'' as [Level3!2]
Union All
Select 2 as Tag,
1 as Parent,
null as [Level2!1],
'' as [Level3!2]
For Xml Explicit
))
SELECT @outputXML
And:
Code:
DECLARE @outputXML as varchar(1024)
select @outputXML = (select Tag,Parent,[Level2!1],[Level3!2] from
(
Select 1 as Tag,
null as Parent,
null as [Level2!1],
'' as [Level3!2]
Union All
Select 2 as Tag,
1 as Parent,
null as [Level2!1],
'' as [Level3!2]
For Xml Explicit
))
SELECT @outputXML
Can anyone help point me in the right direction ?
Thanks in advance.