SQL to list requirment with parent child relationship
Question ID: 104562
6
0

Does anyone have a SQL to list requirements including the Parent/Child relationships?
Thanks in Advance.
DW

Marked as spam
Posted by (Questions: 70, Answers: 111)
Asked on August 7, 2012 7:08 pm
76 views
Answers (1)
3
Private answer

Here you go.....

**SQL STATEMENT**

WITH REQ_CTE AS (
SELECT RQ_REQ_ID, RQ_FATHER_ID, RQ_REQ_NAME, TPR_NAME, RQ_REQ_PATH, 1 AS LVL
FROM td.REQ
INNER JOIN td.REQ_TYPE RT ON RT.TPR_TYPE_ID = RQ_TYPE_ID
WHERE RQ_FATHER_ID = 0
UNION ALL
SELECT r.RQ_REQ_ID, r.RQ_FATHER_ID, r.RQ_REQ_NAME, RT2.TPR_NAME, r.RQ_REQ_PATH, LVL + 1
FROM td.REQ r
INNER JOIN td.REQ_TYPE RT2 ON RT2.TPR_TYPE_ID = r.RQ_TYPE_ID
INNER JOIN REQ_CTE ectr ON ectr.RQ_REQ_ID = r.RQ_FATHER_ID
)
SELECT RQ_REQ_ID AS ID, RQ_FATHER_ID AS PARENT, SPACE(LVL * 4) + RQ_REQ_NAME AS NAME, TPR_NAME AS TYPE
FROM REQ_CTE
ORDER BY RQ_REQ_PATH

**SQL RESULTS**
![alt text][1]

[1]: /upfiles/SQL_RECURSIVE_8-7-2012_6-15-43_PM.jpg

Marked as spam
Posted by (Questions: 0, Answers: 613)
Answered on August 7, 2012 7:19 pm
0
Many Thanks for the Quick Reply!!!!
( at August 7, 2012 7:25 pm)
EyeOnTesting

Welcome back to "EyeOnTesting" brought to you by Orasi Software, Inc.

X
Scroll to Top