Link to home
Start Free TrialLog in
Avatar of ramos_rita
ramos_ritaFlag for United States of America

asked on

Reseed temp autonumber before insert

I am working on an insert that is taking a flat file and it splits into two tables for our accounting system.  
The original file will look something like this...
ID,Desig1,Desig1Amount,Desig2,Desig2Amount,Desig3,Desig3Amount (up to 8 Designations)
1233,A,10.00,B,10.00,C,10.00,D,20.00
1234  etc.
The Batch tables
Result would be
TABLE A
BCHNUM, BCHSEQ, ID
55555,1,1233
TABLE B
BCHNUM BCHSEQ, DESIGSEQ, DESIG, DESIGAmount
55555,1,1,A,10.00
55555,1,2,B,10.00
55555,1,3,C,10.00
55555,1,4,D,20.00
55555,2,1,A,10.00
etc
Each person can have between 1 and 8 designations, each designation can only be designated to once by each person, if the person designates to the same place twice, the amounst should be added together and only one row inserted.  the seed for desigseq must reset to 1 each time a new person is inserted and count up to 8 or the highest number of designations they have.  
The only ideas i have is nesting cursors and reseeding my temp tables.  
I must use t-sql for this.  I am converting an ssis package that did this into t-sql due to restrictions on the ssis runtime.  Lots of people will be running this at the same time.
Thank You...

Avatar of Racim BOUDJAKDJI
Racim BOUDJAKDJI
Flag of Algeria image

Avatar of ramos_rita

ASKER

I know how to reseed the problem is how do I ROWNUMBER or AUTONUMBER based on a condition resetting... in this case i have a new donor and he has more than one designations that i have to insert bu their seed value.

I know there must be a way to do this with XML or WHILE loops or something that I can get it done.
>>I know how to reseed the problem is how do I ROWNUMBER <<
Then perhaps you should look at the ROW_NUMBER() function together with the PARTITION clause.  Unfortunately, I cannot help you any further as I am not following your comments at all.
ASKER CERTIFIED SOLUTION
Avatar of Raja Jegan R
Raja Jegan R
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
To me this seems more like a work around and would not work on any large scale (100's of rows across ... ) but absolutely worked in this case.  
in regards to the other comments on not understanding my issue.  
I guess maybe I didn't ask the question clearly ...