Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

tsgl -can you get the Scope_Identity for each record added in when Inserting  mulitple records in a table

Posted on 2012-03-26
4
Medium Priority
?
331 Views
Last Modified: 2012-03-26
I have a stored procedure that is adding muliple records when it is runs.
What I want to do is build a work file with the Scope_Identity() 'key" of each record I add.
Well for one of the tranactions.
I do have 3 tranacations in this stored procedure

1) delete all records in a work table


2) insert all records
  So when this runs it usually adds 30/40 records a run. I want to build in another work table with the Scope_Identity() = key of record added.



3) add comment records
0
Comment
Question by:john M
  • 2
4 Comments
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 37767238
It appears Scope_Identity works within a transaction. Have you tried it?
0
 
LVL 3

Author Comment

by:john M
ID: 37767309
i am not sure how to get it.

i know you can  set it
 set keyfound = scope_idenity()

insert into filea
(ssn,
name)
select
ssn,
name
from
bfileb
how are you getting it?

then how do you provide to write a tempwork Table?

insert into tempfiles
(keyoflastrecord,
date)
select
scope_idenity()
date
from
filec
0
 
LVL 18

Accepted Solution

by:
UnifiedIS earned 2000 total points
ID: 37767626
You won't be able to get the identity for each record unless your insert only adds one record at a time.

In other words, if you are doing a INSERT INTO..SELECT FROM where the SELECT FROM will have many values, it won't provide the intended results

.
0
 
LVL 3

Author Closing Comment

by:john M
ID: 37767665
good to know it can't be done
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses
Course of the Month21 days, 3 hours left to enroll

810 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