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 |
|
Tigger
Yak Posting Veteran
85 Posts |
Posted - 2002-02-27 : 14:47:54
|
| I need to create a table which has in itparty_id - identity columnbranch_numberbranch_idwhere branch_id is an identity column within branch.egparty_id branch_number branch_id 1 123 12 456 13 123 24 123 35 456 2Customer data is going to be imported into the table using DTS and will be assigned a party_id and branch_id.Any ideas on how to generate branch_id or is this one of those cases where we will have to process the records one row at a time ? |
|
|
jbkayne
Posting Yak Master
100 Posts |
Posted - 2002-02-27 : 16:26:59
|
| Try the following:--drop table partycreate table party (party_id int identity(1,1) not null, branch_number int not null, branch_id int not null)declare @feed table ( branch_number int not null , randomizer int identity(1,1) not null)insert into @feed (branch_number)select 123 as branch_numberunion allselect 456union allselect 123insert into party (branch_number, branch_id)select branch_number , isnull((select max(branch_id) from party as p where p.branch_number = feed.branch_number),0) + (select count(*) from @feed as feed2 where branch_number = feed.branch_number and randomizer <= feed.randomizer) as branch_idfrom @feed as feedselect * from partyEdited by - jbkayne on 02/27/2002 16:37:17 |
 |
|
|
|
|
|