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

Copy data in existing table into same table with self reference

$
0
0

Hello

Following is the example table.

SelfRefTable

Id        Name                ParentId        Year

1         GrandParent             null        2013

2         Parent                          1        2013

3         Child                             2        2013

4         GrandChild                   3        2013

Id column is Identity column. ParentId references Id column(Self reference).

Now I want to duplicate above data in the same table with incremented Year.

Following should be the table data after duplication.

SelfRefTable

Id        Name                ParentId        Year

1         GrandParent             null        2013

2         Parent                          1        2013

3         Child                             2        2013

4         GrandChild                   3        2013

5         GrandParent             null        2014

6         Parent                          5        2014

7         Child                             6        2014

8         GrandChild                   7        2014

Please somebody help me to do this

Thanks in advance

Sanandan




Viewing all articles
Browse latest Browse all 23857

Trending Articles



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