I am getting an error with the following code. Can anyone help?
Error message:
Only one expression can be specified in the select list when the subquery is not introduced with EXISTS.
If I change the code to this I get another error message.
Error Message:
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.
Error message:
Only one expression can be specified in the select list when the subquery is not introduced with EXISTS.
Code:
DECLARE @StrXML NVARCHAR(MAX)
SET @StrXML =
(
SELECT
(
SELECT 'This', 'is', 'a', 'test 1'
UNION
SELECT 'This', 'is', 'a', 'test 2'
)
FOR XML PATH('Test'), ELEMENTS, ROOT('MyRoot')
)
If I change the code to this I get another error message.
Error Message:
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.
Code:
DECLARE @StrXML NVARCHAR(MAX)
SET @StrXML =
(
SELECT 'This', 'is', 'a', 'test 1'
UNION
SELECT 'This', 'is', 'a', 'test 2'
FOR XML PATH('Test'), ELEMENTS, ROOT('MyRoot')
)