sql server - Determine the hierarchy of records in a SQL database -


I am getting a problem, I was wondering if there is a beautiful solution, this is a real business problem and class assignment is not!

I have thousands of records, some of which are related to each other

The database is SQL 2005.

The ID is the primary key if the record has changed an earlier record, then the ID of that record is in the REP_ID column.

  ID REP_ID EDDBCBBAA NULL  

Then in this example, the A was the original line, B place A, C replacement B failed, D replacement B. successfully and finally E in place of D.

I want to be able to display all records in this table in a grid. Then, I want the user to be able to click on any record in any group, and to find the system in all related records and to display in any type of tree.

Now I am obviously able to do this to solve the overwhelming force, but I would like to ask the community whether they can see a more elegant answer. Use one to create your hierarchy, some things like #TestValue ('E', & quot;

Code> Table # Test (ID Chair (1), RP_IDTR (1) F) '' D ',' B ') # Test Value INSERT Insert ('C', 'B') into #Test Value ('B', 'A') with the tree in the #Test Value ('A', NULL) (ID, REP_ID, Depth) (Selection ID, REP_ID, 1AS [Depth] from #Test Where REP_ID Ion is selected [test] .IID, [test] .repe_id, tree. [Depth] + 1 AS [Depth] to log on tree with #Test [Exam] [Exam] .REP_ID = tree.ID) Select tree

Comments

Popular posts from this blog

asp.net - Javascript/DOM Why is does my form not support submit()? -

sockets - Delphi: TTcpServer, connection reset when reading -

javascript - Classic ASP "ExecuteGlobal" statement acting differently on two servers -