Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
loken.bhatt
Starting Member
5 Posts |
Posted - 2007-03-12 : 06:42:04
|
| HiI have a table named UserProfile with following structure :(TypeId bigint,TypeName nvarchar(100),ParentTypeId bigint)Have some following sample data :TypeId TypeName ParentTypeId1 User 02 Artist 13 Singer 24 DJ 15 Band 16 Partner 07 Movies 68 GoodMovies 79 BadMovies 710 Producer 6I want to generate the XML in following form<Main> <TypeId>1</TypeId> <TypeName>User</TypeName> <ParentTypeId>0</ParentTypeId> <SubProfiles> <SubProfile> <TypeId>2</TypeId> <TypeName>Artist</TypeName> <ParentTypeId>1</ParentTypeId> </SubProfile> <SubProfile> <TypeId>4</TypeId> <TypeName>DJ</TypeName> <ParentTypeId>1</ParentTypeId> </SubProfile> <SubProfile> <TypeId>5</TypeId> <TypeName>Band</TypeName> <ParentTypeId>1</ParentTypeId> </SubProfile> </SubProfiles></Main>I am usign CTE for recursive query and then using for xml auto mode to generate xml. But the data is not generating when the parent child relation is in depth level.Kindly anybody tell me the query so that I can generate the xml in heirarchical order of data. |
|
|
jezemine
Master Smack Fu Yak Hacker
2886 Posts |
Posted - 2007-03-12 : 12:24:20
|
for fine grained control of the xml, have a look at FOR XML PATH syntax.stay away from FOR XML EXPLICIT at all costs. It is a horrid thing. www.elsasoft.org |
 |
|
|
snSQL
Master Smack Fu Yak Hacker
1837 Posts |
Posted - 2007-03-12 : 13:27:45
|
| Post the query you're using now, and someone can help you fix it. |
 |
|
|
loken.bhatt
Starting Member
5 Posts |
Posted - 2007-03-15 : 01:00:14
|
quote: Originally posted by snSQL Post the query you're using now, and someone can help you fix it.
I am using the following query :With Heirarchy as(Select TypeId,TypeName,ParentTypeId,0 as [Level] from UserProfileTypeDummyTable where ParentTypeId=0Union AllSelect UserProfileTypeDummyTable.TypeId,UserProfileTypeDummyTable.TypeName,UserProfileTypeDummyTable.ParentTypeId, [Level]+1 from Heirarchy inner join UserProfileTypeDummyTable onHeirarchy.TypeId=UserProfileTypeDummyTable.ParentTypeId)Select Heirarchy.TypeId,Heirarchy.TypeName,Heirarchy.ParentTypeId,SubProfile.TypeId,SubProfile.TypeName,SubProfile.ParentTypeId from Heirarchy inner join UserProfileTypeDummyTable as SubProfileon SubProfile.ParentTypeId=Heirarchy.TypeIdfor XML Auto,elements,typeplease reply to generate the heirarchical data in xml from db |
 |
|
|
|
|
|
|
|