Technical advise and questions area

Moderators: Seth, fireman_343, MOTOHEAD52, JReid

help needed on tree level sql?

Postby Williamhawk » Tue Oct 17, 2017 3:58 am


There are 2 tables, Names(id int identity(1,1), name varchar(255)) and Relationships (nameid int, parent_nameid int) linked via = Relationships.namesid and where top-most name has a parent_nameid = 0. Show a nested list of names including level, nameid and name where level indicates the nest level (or depth) from the top, as indicated in the expected output (below). You may use functions, stored procedures, views and any other Transact SQL commands compliant with MS SQL 2000. Sample Data. Names table content: id name 1 Frank 2 Jo 3 Mary 4 Peter 5 Amy Relationships table content: nameid parent_nameid 1 0 2 1 3 2 4 1 5 2 Expected Output In the expected output, please note 1. The purpose - rather than just the value - of the Level column 2. The sequence of the output, in which child elements appear immediately beneath their respective parent elements.

Please help.

I didn't find the right solution from the Internet.


creative animation video
Corner worker
Posts: 38
Joined: Thu Sep 21, 2017 3:47 am
  • Abuse

Forum Statistics

Who is online

Users browsing this forum: No registered users and 1 guest


Return to Tech Questions