Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

Need a logic to generate serial number for the items having parent and child mappings

$
0
0

Need a logic to generate serial number for the items having parent and child mappings.

Below is the image showing the sample item mapping( the real system has more than 20 levels) with four levels.

The generated mapping should be 

100- 1

102- 2

104- 3

106 -4

105 -5

109 -6

103- 7

107- 8

The sample data generation scripts ,

create table #test(Childid int, parentid int, Sno int)

insert into #test (Childid,parentid)
values (100,0),(102,100),(103,100),(104,102),(105,102),(106,104),(107,103),(109,105)

select * from #test

Any help is appreciated.


Please use Marked as Answer if my post solved your problem and useVote As Helpful if a post was useful.



Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>