?
Solved

Reseed temp autonumber before insert

Posted on 2009-07-08
5
Medium Priority
?
429 Views
Last Modified: 2013-11-10
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...

0
Comment
Question by:ramos_rita
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 23

Expert Comment

by:Racim BOUDJAKDJI
ID: 24806490
0
 

Author Comment

by:ramos_rita
ID: 24807750
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.
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 24808760
>>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.
0
 
LVL 57

Accepted Solution

by:
Raja Jegan R earned 1500 total points
ID: 24810156
Thinking out of the box:

you can insert the records from Flat file into one of your Temp table.
Once it is done, you can intercept the records for your two tables like this.

I have included columns ID,desig,desigamount only. Include your other columns like BCHNUM, BCHSEQ, ID over here during your processing and insert into your tables accordingly.

Kindly revert if I need to explain more on the logics.
select ID,desig,desigamount
from (
SELECT ID,Desig1 as desig, Desig1Amount as desigamount, 1 as DESIGSEQ
from urtable
union all
SELECT ID,Desig2, Desig2Amount, 2
from urtable
union all
SELECT ID,Desig3, Desig3Amount, 3
from urtable
union all
SELECT ID,Desig4, Desig4Amount, 4
from urtable
union all
SELECT ID,Desig5, Desig5Amount, 5
from urtable
union all
SELECT ID,Desig6, Desig6Amount, 6
from urtable
union all
SELECT ID,Desig7, Desig7Amount, 7
from urtable
union all
SELECT ID,Desig8, Desig8Amount, 8
from urtable ) temp
where desig is not null

Open in new window

0
 

Author Closing Comment

by:ramos_rita
ID: 31601241
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 ...
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have a large data set and a SSIS package. How can I load this file in multi threading?
A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question