Solved

Reseed temp autonumber before insert

Posted on 2009-07-08
5
425 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 500 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

Free eBook: Backup on AWS

Everything you need to know about backup and disaster recovery with AWS, for FREE!

Question has a verified solution.

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

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

763 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