Solved

Duplicate rows in Datatable

Posted on 2008-06-21
3
1,997 Views
Last Modified: 2008-06-23
I hava a datatable with 10 rows.  I need to duplicate those rows. How is best to do this?
(Then I will add another column to identify each row. ).
0
Comment
Question by:johnkainn
3 Comments
 
LVL 2

Expert Comment

by:Deepika_Rastogi
ID: 21837252
U want to do that through code or your database query
0
 

Author Comment

by:johnkainn
ID: 21837351
I need actually to duplicate 5 times. I need also to create a new column so that each duplicate has its own number in that column, ranging from 1 to 5.
Originally I planned to do this in code, but maybe it is better to do this in SPROC. What do you think?
 Can you help me with that or should I post the question again for the sql group in this forum?
0
 
LVL 11

Accepted Solution

by:
CMYScott earned 125 total points
ID: 21839365
the SPROC would be like this...  (you'll need to add the CREATE PROCEDURE heading etc)

select * into #temp from yourtable
alter table yourtable add idx int
go
update yourtable set idx = 1
insert into yourtable select #temp.*,2 from #temp
insert into yourtable select #temp.*,3 from #temp
insert into yourtable select #temp.*,4 from #temp
insert into yourtable select #temp.*,5 from #temp
drop table #temp
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

912 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now