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.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Append a table with 1:n relationship

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2000-10-29 : 15:37:34
Thorsten writes "Hello everyone,

the following nut to crack in T-SQL as a stored procedure, on WinNT4 SP6a, SQL Server 7 with SP2.

I have two tables, both have the same structure.

NodeID int
ParentID int
Level int

The first columns are identifiers for nodes in a classic 1:n
parent/child-relationship. The last column Level contains the level of the node in the hierarchy, the root/first node having 0, the last ones having n. The NodeIDs are linked to an appropriate table holding data.

Both tables contain different structures, e.g. products in table A, and regions in table B. If I want to show the user a customizable structure in an explorer-like treeview, I have to append a table to the other. This can happen on any level, eg. drilling down in table B (Regions) from World via continents to countries, and then switching to table A (Products), thus showing the user the turn-over of product groups or products per country (and vice versa, if needed).

For any node on the first level of the different structure that will be appended, I have to change the value of Level (to reflect the position in the new temporary hierarchy) and, most important, the ParentID for Nodes in the first level in structure to be appended (to glue the structures together).

If anyone has a decent idea, I would be very, very grateful

Thorsten"
   

- Advertisement -