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
328 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
[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
  • 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 500 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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

707 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