See:
https://www.codeproject.com/Articles/818694/SQL-Queries-to-Manage-Hierarchical-or-Parent-child
Your sample data does not include any records for the parent 1010.
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
I have data like below, just an example:
CREATE TABLE #Temp (ID int, ChildID INT, ParentID INT)
INSERT INTO #Temp
SELECT 1, 1010, NULL UNION ALL
SELECT 2, 11, 1010 UNION ALL
SELECT 3, 12, 1010 UNION ALL
SELECT 4, 13, 1010 UNION ALL
SELECT 5, 14, 11 UNION ALL
SELECT 6, 15, 11 UNION ALL
SELECT 7, 16, 13 UNION ALL
SELECT 8, 17, 1010 UNION ALL
SELECT 9, 18, 1010
SELECT * FROM #Temp t
I need to find few examples where a ParentID has Childs and a Child out of that list again has Childs and so on.
See:
https://www.codeproject.com/Articles/818694/SQL-Queries-to-Manage-Hierarchical-or-Parent-child
Your sample data does not include any records for the parent 1010.
Sure, Updated.
Hi @Kumar
Have you validate all the answers so far and provide any update?
If all of the answers are not working or helpful, please share with us your confusion or more details about this issue.
And don't forget to accept the answers if they helped. Your action would be helpful to other users who encounter the same issue and read this thread.
Thanks for your understanding!