I wrote my first t-sql for xml explicit in query analyzer using sql server 2000, but I get the error "Parent tag ID 3 is not among the open tags. FOR XML EXPLICIT requires parent tags to be opened first. Check the ordering of the result set."
However, when I remove the last union, it works fine!
I have looked into other forums, and found that it has something to do with sorting. but I have no sorting defined. Also, one forum mentioned values being nulls which is not the case either.
I have only reached the stage where I am trying to define my tags and haven't yet retreived any data from any tables.
Hope any one can help.
sql is as follows:
select
1 as tag,
'' as parent,
'' as [TRNS!1],
'' as [TRN_IN!2],
'' as [TRN_ATRIB!3],
'' as [TRN_ORIGN!4],
'' as [TRN_ID!5]
union
select
2 as tag,
1 as parent,
'' as [TRNS],
'' as [TRN_IN],
'' as [TRN_ATRIB],
'' as [TRN_ORIGN],
'' as [TRN_ID]
union
select
3 as tag,
2 as parent,
'' as [TRNS],
'' as [TRN_IN],
'' as [TRN_ATRIB],
'' as [TRN_ORIGN],
'' as [TRN_ID]
union
select
4 as tag,
2 as parent,
'' as [TRNS],
'' as [TRN_IN],
'' as [TRN_ATRIB],
'' as [TRN_ORIGN],
'' as [TRN_ID]
union
select
5 as tag,
3 as parent,
'' as [TRNS],
'' as [TRN_IN],
'' as [TRN_ATRIB],
'' as [TRN_ORIGN],
'' as [TRN_ID]
for xml explicit
husainfb