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
 Transact-SQL (2000)
 SQL Query

Author  Topic 

madhulatha_b
Starting Member

22 Posts

Posted - 2006-05-27 : 07:28:47
I have two tables Node1,Treenode1

These two tables contains the project related information

Project Structure is

Project
|
Area
|
Site
|
Product

The structure of treenode is

NodeId
NodeParentID
Type
.
.



NodeId contains Id of the node like project,area etc
NodeParentId contains ID of the Parent node.
Type contains level of the node

ex: for project node there no parent so it will have NULL.
For Area, Project NodeId become NodeparentID of Area and so on



The data in treenode will be in the following manner

NodeID NodeParentID Type
P1 Null 1 ----> Project
A2 P1 2 ----> Area
A3 P1 2 -----> Area
S4 A2 3 ---->Site
S5 A2 3 ----> Site
S6 A3 3 ---->Site
S7 A3 3 ---->Site
R4 S4 4 ---->Product
R5 S5 4 ---->Product
R6 S6 4 ---->Product
R7 S7 4 ---->Product




Node1 contains only Project related records
Treenode contains Project and child records i.e project,area,site and product details

Now I want to delete all projects which are older than one year. For that I need to delete records from node1 and treenode

for that First I am fetching the records from node1

select Node into #NA1
from node1
where datediff(day,project_Releasedate,getdate()) > 365

Based on #NA1 I am fetching the project details from treenode

select NodeID,NODEparentID,type into #tmp_treenode
from treenode
where NODEID in (select node from #NA1)

I have project records in #treenode. Now I need to fetch child records from treenode.

Is it possible to fetch all child records using single query

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-05-27 : 07:39:20
Refer this
http://www.nigelrivett.net/RetrieveTreeHierarchy.html

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -