Skip to main content
edited body; edited tags
Source Link
Jon Seigel
  • 12.5k
  • 8
  • 61
  • 93

I have a table as shown below.

ID  ParentID    Node Name       Node Type
------------------------------------------------------------------
525 524     Root            Area Level 1
526 525     C           Area Level 2
527 525     A           Area Level 2
528 525     D           Area Level 2
671 525     E           Area Level 2
660 527     B           Area Level 3
672 671     F           Area Level 3

How can i write a recursive t-sql query to generate below output?

Output ("Root" node not required in the output):

Node        ID
-----------------------
A       527
A/B     660
C       526
D       528
E       671
E/F     672

Thanks

I have a table as shown below.

ID  ParentID    Node Name       Node Type
------------------------------------------------------------------
525 524     Root            Area Level 1
526 525     C           Area Level 2
527 525     A           Area Level 2
528 525     D           Area Level 2
671 525     E           Area Level 2
660 527     B           Area Level 3
672 671     F           Area Level 3

How can i write a recursive t-sql query to generate below output?

Output ("Root" node not required in the output):

Node        ID
-----------------------
A       527
A/B     660
C       526
D       528
E       671
E/F     672

Thanks

I have a table as shown below.

ID ParentID Node Name  Node Type
------------------------------------------------------------------
525 524  Root   Area Level 1
526 525  C   Area Level 2
527 525  A   Area Level 2
528 525  D   Area Level 2
671 525  E   Area Level 2
660 527  B   Area Level 3
672 671  F   Area Level 3

How can i write a recursive t-sql query to generate below output?

Output ("Root" node not required in the output):

Node  ID
-----------------------
A  527
A/B  660
C  526
D  528
E  671
E/F  672

Thanks

deleted 18 characters in body
Source Link
stackoverflowuser
  • 22.4k
  • 31
  • 73
  • 93

I have a table as shown below.

 ID   ParentID    Node Name       Node Type
------------------------------------------------------------------
525 524  524   Root            Area Level 1
526 525  525   C           Area Level 2
527 525  525   A           Area Level 2
528 525  525   D           Area Level 2
671 525   525  E           Area Level 2
660 527   527  B           Area Level 3
672 671   671  F           Area Level 3

How can i write a recursive t-sql query to generate below output?

Output ("Root" node not required in the output):

Node        ID
-----------------------
A       527
A/B     660
C       526
D       528
E       671
E/F     672

Thanks

I have a table as shown below.

 ID   ParentID Node Name  Node Type
------------------------------------------------------------------
525   524  Root    Area Level 1
526   525  C   Area Level 2
527   525  A   Area Level 2
528   525  D   Area Level 2
671   525  E   Area Level 2
660   527  B   Area Level 3
672   671  F   Area Level 3

How can i write a recursive t-sql query to generate below output?

Output ("Root" node not required in the output):

Node  ID
-----------------------
A  527
A/B  660
C  526
D  528
E  671
E/F  672

Thanks

I have a table as shown below.

ID  ParentID    Node Name       Node Type
------------------------------------------------------------------
525 524     Root            Area Level 1
526 525     C           Area Level 2
527 525     A           Area Level 2
528 525     D           Area Level 2
671 525     E           Area Level 2
660 527     B           Area Level 3
672 671     F           Area Level 3

How can i write a recursive t-sql query to generate below output?

Output ("Root" node not required in the output):

Node        ID
-----------------------
A       527
A/B     660
C       526
D       528
E       671
E/F     672

Thanks

Source Link
stackoverflowuser
  • 22.4k
  • 31
  • 73
  • 93

Recursive t-sql query

I have a table as shown below.

 ID   ParentID Node Name  Node Type
------------------------------------------------------------------
525   524  Root    Area Level 1
526   525  C   Area Level 2
527   525  A   Area Level 2
528   525  D   Area Level 2
671   525  E   Area Level 2
660   527  B   Area Level 3
672   671  F   Area Level 3

How can i write a recursive t-sql query to generate below output?

Output ("Root" node not required in the output):

Node  ID
-----------------------
A  527
A/B  660
C  526
D  528
E  671
E/F  672

Thanks