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.
| Author |
Topic |
|
sqllearner
Aged Yak Warrior
639 Posts |
Posted - 2004-06-04 : 02:15:38
|
| I have a table with id and its duplication that should be used in table 2.Now I have table generated with the duplication_id for the corressponding id.Scripts for table 1 I haveTable1id Duplication_id---------------------------1A 5001A 5011A 5027D 5037D 5049G 5059G 506In table 2 I need to do a join with a table 1 so that I will generate a duplicate data for t he series as shown below.Now the key is the primary key and its not a auto number so when i duplicate i should be able to do max(key)+1 so that as u duplicate just the data for each series,the key get incremented each time.The final out out looks like as given belowTable 2key id item-------------------------1 1A cell4 7D watch6 9G camera7 500 cell8 501 cell9 502 cell10 503 watch11 504 watch12 505 camera13 506 camera please help me out |
|
|
ditch
Master Smack Fu Yak Hacker
1466 Posts |
Posted - 2004-06-04 : 03:10:06
|
| something like this maybe:declare @maxkey intset @maxkey = (select max(key) from table2)create table #test(key int identity, duplication_id int, item varchar(50))insert into #testselect a.duplication_id, b.itemfrom table1 ajoin table2 b on a.id = b.idselect @maxkey + key, duplication_id, itemfrom #testDuane. |
 |
|
|
|
|
|