Questions tagged [scope-identity]

122 questions
0
votes
1 answer

How can i get the SCOPE_IDENTITY() From SP?

Im trying to get the SCOPE_IDENTITY to my vb.NET App from a Stored Procedure But i get DBNull Exception. This is my SP: ALTER PROCEDURE [dbo].[sp_XYZ] @ID INT, @OtherID INT OUTPUT AS BEGIN SELECT @Name = name, FROM dbo.PERSON WHERE id =…
0
votes
2 answers

How to use PHP to return the last inserted ID on an MSSQL table with Triggers installed

I am attempting to run a query on an MSSQL database and return the insert ID using PHP. Previously, I had been using the following code for this, which worked fine: $q = "INSERT INTO Pricing (Products_idProducts,FromQty,ToQty,Price)…
Typel
  • 1,109
  • 1
  • 11
  • 34
0
votes
2 answers

TSQL Use record currently being inserted to select data in another table

Very new to TSQL... I have the following table called "tblinit": Account_Num UserID Task_Percent ----------- ------------ ------------ 1 john.smith 0.75 I would like to update the "Task Percent" value in "tblRaw"…
Shrout1
  • 2,497
  • 4
  • 42
  • 65
0
votes
2 answers

Need some t-sql clarification

This is a follow up to my previous question, in t-sql SELECT SCOPE_IDENTITY() returns a BIGINT, I did the following to get it to return an INT: DECLARE @X INT INSERT ... SELECT @X = SCOPE_IDENTITY() -- if i don't include the line below, it…
roman m
  • 26,012
  • 31
  • 101
  • 133
0
votes
2 answers

SCOPE_IDENTITY() after TableAdapter Update, using BindingSource

Trying to get the Autoincrement ID of a row after TableAdapter.Update. The data is Binded so there's no row being added to the datatable as in this case. Any ideas on how to solve this? Thank you
Gil
  • 33
  • 1
  • 11
0
votes
1 answer

SCOPE_IDENTITY() after TableAdapter Update

I've updated my TableAdapter's advanced options, so it would Refresh the data table. I'm looking to retrieve the SCOPE_IDENTITY of the new added row, right after I use TableAdapter.Update. How can this be achieved? Thanks!
Gil
  • 33
  • 1
  • 11
0
votes
2 answers

SCOPE IDENTITY not allowed on a REMOTE server?

I am trying to copy data from 2 tables linked by a foreign key on one server and then inserted them into the master database on another server. The first table will generate a new IDENTITY column and then I want to store this in a variable and…
Chris Wood
  • 535
  • 9
  • 28
0
votes
1 answer

Correct way to use SCOPE_IDENTITY()?

I have 2 separate forms. The first form handler determines if the second form is needed. Each form populates a separate database table. I need to be able to link corresponding rows later. I am trying to do so by calling SCOPE_IDENTITY() after the…
cream
  • 1,129
  • 5
  • 16
  • 26
0
votes
0 answers

SCOPE_IDENTITY() always returns NULL + SSIS

This is my script where I grab SCOPE_IDENTITY() and assign to SSIS Package variable. --START: SCRIPT TO CHECK IF THERE IS ENTRY FOR 'UNKOWNN' IN AUDIT DIMESNION - IF NOT INSERT IF NOT EXISTS (SELECT AUDIT_SK FROM SHARED.AUDIT_DIM WHERE AUDIT_SK =…
Sreedhar
  • 29,307
  • 34
  • 118
  • 188
0
votes
1 answer

ms sql scope_identity

I want to pass the id of the last inserted tuple in the stored procedure as an argument to another stored procedure. Here are four snippets of code. The first two snippets works correctly: declare @s bigint select @s = scope_identity() exec…
superM
  • 8,605
  • 8
  • 42
  • 51
-1
votes
2 answers

SCOPE_IDENTITY returns null until an error is thrown in MS Access

MS Access front-end with a SQL Server back-end, using pass-through queries in Access over OBDC connection. No ADO, just simple DAO query objects. After an INSERT query is executed, a "SELECT SCOPE_IDENTITY()" query is run to retrieve the ID of the…
JoshL
  • 1
  • 1
-1
votes
1 answer

PK of Table 1 as a FK in Table 2 using SQL and C# - breaks with select_identity(), Object cannot be cast from DBNull to other types

C# and SQL beginner here. I have two tables using primary key of table1 as a foreign key in table2. To get an ID, I'm using SELECT MAX and everything works as I want (code below): { con1.Open(); SqlCommand cmd1 = new…
alexx_slo
  • 1
  • 1
-1
votes
2 answers

ExecuteSQLCommand SCOPE_IDENTITY() always return 1 (.NET C#)

I'm using dynamic sql for insert data into dynamic table (.NET C#). I need to get the identity column value in return and I try to use scope_identity but the result always shows 1. This is my code dqDbContext dqx = new dqDbContext(); string queryHdr…
-2
votes
2 answers

SQL Server equivalent for Oracle IDENTITY_VAL_LOCAL() function

I am in the middle of a project where we are moving from Oracle to SQL Server. I was wondering if, like the title says,there are any SQL Server equivalent for Oracle's built in function IDENTITY_VAL_LOCAL(). The SQL statement that I am looking at…
VianneN
  • 143
  • 3
  • 12
-2
votes
1 answer

Stored Procedure and Scope_Identity() SQL

I'm trying to create a stored procedure the inserts values into two tables tblAirport and tblCountry. tblAirport has a FK that references tblCountry and I want to insert the values to tblCountry using the values from the FK in tblAirport. I'm new to…
Tat Scagliotti
  • 69
  • 2
  • 2
  • 4
1 2 3
8
9