March 14, 2009 at 2:11 am
IDParentidName
1NULLSearch
2NULLWS
3NULLEnter
4NULLArts
51Name1
106Name2
258Name3
268Name4
319Name4
3210Name5
Hi All
I have implemented the recursive CTES for getting the data in Parent-Child relationship.
But my requirement is that i have get the details about the parentid's along with the recursive data' in a single join
When I give the Id
When i Select with the ID,Both Child and Parent should be displyed in join
Thanx
RAO
March 14, 2009 at 4:11 am
Since you already implemented the parent-child recursion using CTE, you can post that query along with some information about the output required for the given input. You mentioned that you want parent details as well in the recursive CTE, so I think you just need to add parent details in the anchor & recursive part of the CTE query.
This is an example of how to get parent information along with child using CTE. Note that this query is not tested (even for syntax), as currently I don't have any SQL at my machine.
;WITH EmployeeCTE
AS
(
SELECT EmployeeID, EmployeeName, NULL AS ManagerID, NULL AS ManagerName, 0 AS EmployeeLevel
FROM Employees
WHERE ManagerID IS NULL
UNION ALL
SELECT E.EmployeeID, E.EmployeeName, C.EmployeeID, C.EmployeeName, C.EmployeeLevel + 1
FROM EmployeeCTE C
INNER JOIN Employees E ON C.EmployeeID = E.ManagerID
)
SELECT * FROM EmployeeCTE ORDER BY EmployeeID, EmployeeLevel
--Ramesh
March 14, 2009 at 9:18 am
my requirement is that i have get the details about the parentid's along with the recursive data' in a single join
Test question?
I've been taking buisness requirements for years, and never once has "in a single join" been specified as a requirement. So who made it mandatory for you?
__________________________________________________
Against stupidity the gods themselves contend in vain. -- Friedrich Schiller
Stop, children, what's that sound? Everybody look what's going down. -- Stephen Stills
March 14, 2009 at 10:42 am
Bob Hovious (3/14/2009)
my requirement is that i have get the details about the parentid's along with the recursive data' in a single join
Test question?
I've been taking buisness requirements for years, and never once has "in a single join" been specified as a requirement. So who made it mandatory for you?
Heh... I've found that most folks that want it in a "single join" or "single query" are doing it because they intend to embed the code in a GUI rather than writing it in a stored proc. That certainly doesn't make it right, though.
--Jeff Moden
Change is inevitable... Change for the better is not.
March 14, 2009 at 10:52 am
I guess I'm lucky that my guys just ask me for stored procedures now. They know I will give them something that runs fast on the front end.
__________________________________________________
Against stupidity the gods themselves contend in vain. -- Friedrich Schiller
Stop, children, what's that sound? Everybody look what's going down. -- Stephen Stills
March 16, 2009 at 6:19 am
Thanx Friends..
March 17, 2009 at 11:02 am
RAO (3/16/2009)
Thanx Friends...... i found the solution....
Would you post it here for the rest of us?
March 18, 2009 at 6:14 am
RAO
March 19, 2009 at 7:22 am
Hi Friends ;
Viewing 9 posts - 1 through 8 (of 8 total)
You must be logged in to reply to this topic. Login to reply