Friday, March 9, 2012

Hierarchy ORBER BY

Hi, I'm trying to figure out how to write I SP on the following table that will produce the results show at the bottom. My main problem is the sorting, is there a way I loop through the records in TSQL and ORDER BY SortSort where the ParentID's are the same?

Thank you.

Table example


IDParentIDSortOrderCaption
1null1Main
211Files
313Folders
422File2
512Holders
621File1
752Holder2
851Holder1

Required result example

Main
-Files
--File1
--File2
-Holders
--Holder1
--Holder2
-FoldersI don't think a simple order by statment can do this job. You may need to develop a stack algorithm and a cursor to loop through records.|||Check this article. That's your answer

www.aspalliance.com/388

AP|||Thank you! I also got some good responses from the sqlteam.com forum at http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=33222

No comments:

Post a Comment