ramos_rita
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,Des ig2,Desig2 Amount,Des ig3,Desig3 Amount (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...
The original file will look something like this...
ID,Desig1,Desig1Amount,Des
1233,A,10.00,B,10.00,C,10.
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...
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 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.
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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 ...
in regards to the other comments on not understanding my issue.
I guess maybe I didn't ask the question clearly ...
http://doc.ddart.net/mssql/sql70/dbcc_5.htm