Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Union-All and For-XML clause

1,177 views
Skip to first unread message

Han

unread,
Jun 30, 2009, 4:24:44 AM6/30/09
to
Hello

I am having difficulties using for-xml clause with union-all. e.g.,

select
case
when 1=1 then (
select 1
union all
select 2
for xml path
)
end

I want <row>1</row><row>2</row>, but meet an error.

Msg 1086, Level 15, State 1, Line 9
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 can't understand the message. How do you "wrap the SELECT ..." ?

I have no problem when there is no case-when block. i.e.,

select 1
union all
select 2
for xml path

Can anyone show me the way "wrap the SELECT ..." ?


-----------------------------------------------------------------------------
Less Spam Better enjoyable experience
Visit : news://spacesst.com

Uri Dimant

unread,
Jun 30, 2009, 5:05:00 AM6/30/09
to

Han
select * from

(

select 1 as a

union all

select 2

) as d for xml path

"Han" <hp4...@kornet.net.korea> wrote in message
news:E24B460D-6430-47F3...@microsoft.com...

Han

unread,
Jun 30, 2009, 8:45:04 PM6/30/09
to

Thanks Uri Dimant

It works.

select
case when 1=1 then
(

select * from
(
select 1 as a
union all
select 2
)

as d for xml path, type
)
end

"Uri Dimant" <ur...@iscar.co.il> 占쏙옙占쏙옙 占쏙옙占쏙옙 占쌨쏙옙占쏙옙占쏙옙 占쌜쇽옙占쌩쏙옙占싹댐옙.
news:eiFQOHW%23JHA...@TK2MSFTNGP05.phx.gbl...

0 new messages