Questions tagged [scope-identity]
122 questions
2
votes
4 answers
Entity Framework and SCOPE_IDENTITY
I have a stored procedure that inserts into a table then executes this line
SET @returnVal = SCOPE_IDENTITY();
and after that I've tried both:
SELECT @returnVal
and
return @returnVal
When I execute the stored procedure from Microsoft SQL Server…

Dudeman3000
- 551
- 8
- 21
1
vote
1 answer
Scope_identity() in batched sqlclient commands
I usually use a stored procedure when inserting records to make sure I get the correct scope_identity() value. I have a requirement to get the id field of an inserted record when using SqlClient now.
My understanding is that if I batch the…

Dave Sumter
- 2,926
- 1
- 21
- 29
1
vote
2 answers
How to get Identity value whith help of scope_identity()
I have scope_identity() that implemented in TRIGGER.
ALTER TRIGGER TempProcTrig
ON Table_temp2
AFTER insert
AS
BEGIN
declare @TempIdentity int
set @TempIdentity =scope_identity()
insert Table_Temp(TempID)
…

Michael
- 13,950
- 57
- 145
- 288
1
vote
2 answers
Trying to pass recent ID with scope_identity, and its error me : Specified cast is not valid
Im trying to pass the recent ID that I just insert with Scope_Identity,
and its giving me some weird stuff.
it says :
: Specified cast is not valid
and refering to the line :
int IdOfRecentHistoryGame =…

thormayer
- 1,070
- 6
- 28
- 49
1
vote
4 answers
Select identity after an unsuccessful insert because of a duplicate
Say I have an MS SQL Server table with a primary key ID and a unique key Name. Also, IGNORE_DUP_KEY is set for Name. What I want to do is to insert a name and then get its ID, regardless of the operation execution success. I.e. if the name is not a…

Shere Khan
- 11
- 3
1
vote
2 answers
How to return the last primary key inserted
I ask about alternative or similar query in informix to perform the following:
INSERT INTO days (depcode,studycode,batchnum) values (1,2,3);SELECT SCOPE_IDENTITY();
I want a query to return the SCOPE_IDENTITY() during insertion statement

Anyname Donotcare
- 11,113
- 66
- 219
- 392
1
vote
0 answers
Value of SCOPE_IDENTITY() when inserting more than one row
The documentation for SCOPE_IDENTITY states that it
Returns the last identity value inserted into an identity column in the same scope.
I wonder what last really means. Is it the largest value inserted in current scope, or the value of row that…

andowero
- 439
- 4
- 13
1
vote
0 answers
Trouble Getting Output Parameter from sp_executesql with input Parameters
I am inserting a row into a remote MS SQL server and want to to retrieve the inserted row ID. I am using sp_executesql and passing in input parameters. The row is inserting but the OUTPUT parameter is null. Any idea why output parameter in NULL:…

VIH
- 11
- 1
1
vote
1 answer
Get multiple scope_identity while inserting data with table-valued parameter
I am inserting multiple rows into Table1 using table-valued parameter.
Now I want to insert Table1's scope identity to Table2 with some values.
How do I achieve that?

Bhavin patel
- 25
- 3
1
vote
3 answers
Capture IDENTITY column value during insert and use as value for another column in same transaction
While performing an insert to a table which has an IDENTITY column, is it possible to use the IDENTITY value as the value for another column, in the same transaction?
For example:
DECLARE @TestTable TABLE
(
…

devklick
- 2,000
- 3
- 30
- 47
1
vote
1 answer
WCF Service Discovery Scope
Scenario:
I have several services that I want to be discovered by different clients. Executing the discovery is working perfectly. But now I have different versions of those services for different reasons.
I might have 3 - 4 different layers in my…

Ryan Pedersen
- 3,177
- 27
- 39
1
vote
3 answers
Getting SCOPE_IDENTITY from SQL Server on Insert
I guess it is too late and I'm too tired to see what I'm doing wrong. Here is what I'm trying:
int imageId = imageDal.AddImage(new SqlParameter[]
{
new SqlParameter("@IMAGE_ID",
SqlDbType.Int, Int32.MaxValue,…

Pabuc
- 5,528
- 7
- 37
- 52
1
vote
0 answers
Azure SCOPE_INDENTITY() DBPARM
when using SQL Server with the Native Client, I get funny results if in the DBParm I do not specify the:
TrimSpaces=1,RecheckRows=1,Identity='SCOPE_IDENTITY()
I am thinking jumping into Azure. Will these DBParms be recognized by Azure?
Also, can I…

PanosPlat
- 940
- 1
- 11
- 29
1
vote
2 answers
SQL Insert from one TVP into two tables, using scope identity from first for second table
I have SQL TVP object with multiple records (for example 2 records).
I need to insert these records into two almost identical tables, the only difference is that second table has one more column which is foreign key pointing to first table. So it…
user3681549
1
vote
1 answer
Is it possible to use two SCOPE_IDENTITY calls in the same procedure?
The way I want my stored procedure to work is this, the user passes all of the customer data, name, phone, and all of address info into the procedure, then I want to perform an insert into the address table, get the id generated from that insert,…

mattgcon
- 4,768
- 19
- 69
- 117