Saturday, June 4, 2016

queries to manage hierarchical or parent-child relational rows in SQL Server

//queries to manage hierarchical or parent-child relational rows Example
WITH q AS
(
SELECT *
FROM MKT1
WHERE ParentID =4
UNION ALL
SELECT m.*
FROM MKT1 m
JOIN q
ON m.parentID = q.PersonID

)
SELECT *
FROM q WHERE 1=1

No comments: