Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Duplicate rows in Datatable

Posted on 2008-06-21
3
Medium Priority
?
2,009 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 500 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

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…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…

636 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