Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 how to duplicate rows in the same table

Author  Topic 

CLages
Posting Yak Master

116 Posts

Posted - 2004-02-22 : 19:00:06
I have a table named TABELA looks like this

Code seq Name Balance
123 01 carlos 123,88
123 02 maria 88,55


Code and Seq are keys, i give a new key (ex. 888) and would like to duplicate the above rows changing only the keys and the table should be:

Code seq Name Balance
123 01 carlos 123,88
123 02 maria 88,55

888 01 carlos 123,88
888 02 maria 88,55

tks
Carlos Lages

simondeutsch
Aged Yak Warrior

547 Posts

Posted - 2004-02-22 : 22:13:52
Create a table of keys and cross join it with the data, then insert it into TableA.

INSERT TableA(Code,seq,Name,balance) SELECT #Keys.Code,T.seq,T.Name,T.Balance FROm #Keys,TableA


Sarah Berger MCSD
Go to Top of Page
   

- Advertisement -