Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
DB Engine
SQL ServerMSDESQL Server CE
Services
Analysis (Data Mining)Analysis (OLAP)DTSIntegration ServicesNotification ServicesReporting Services
Programming
CLRConnectivitySQLXML
Other Technologies
ClusteringEnglish QueryFull-Text SearchReplicationService Broker
General
Data WarehousingPerformanceSecuritySetupSQL Server ToolsOther SQL Server Topics
DirectoryUser Groups
Related Topics
MS AccessOther DB ProductsMS Server Products.NET DevelopmentVB DevelopmentJava DevelopmentMore Topics ...

SQL Server Forum / DB Engine / SQL Server / July 2008

Tip: Looking for answers? Try searching our database.

Stored Prcedure Help.

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
kdsv - 08 Jul 2008 13:04 GMT
Dear Friends,

Dear Friends,

I would like to write a stored prcedure which reads data from one
table and inserts into different table.
The data in one table is actually coming from Stored procedure, so the
data is dynamic and can have multiple parent child relation ships
within the same table.  Below I am showing some sample data

id ==> identity column

id parent_id description
1       0            test1
2       1            test2
3       1            test3
4       2            test4
5       2            test5
6       3            test6
7       3            test7
8       5            test8
9       6            test9
10     9            test10

As you see above id is parent_id for some other record.
one id can have multiple children or it may not have any children like
id 1.

Now, I want to write a stored procedure based on the above relations
and copy the data exactly into new table maintaining same parent child
relation ships.  But since id is the identity column when I insert the
record it comes up with new id, so I have to maintain the id and
associate that newly generated ID to the parent_id filed based on
above relations.

so from the above example data, I want to get the data like below.

id   parent_id description
11        0         test1
12       11        test2
13       11        test3
14       12        test4
15       12        test5
16       13        test6
17       13        test7
18       15        test8
19       16        test9
20       19        test10

Your help would be greatly appreciated.

Thanks,
Kdsv

Any ideas/suggestions are really appreciated.

Thanks,

Kdsv
Roy Harvey (SQL Server MVP) - 08 Jul 2008 14:05 GMT
Have you considered using SET IDENTITY_INSERT ON?  That would allow
copying the data without generating new identify values IF there are
no conflicts with values already in the target table.

Roy Harvey
Beacon Falls, CT

>Dear Friends,
>
[quoted text clipped - 55 lines]
>
>Kdsv
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.