0

I am using SqlTransaction.BeginTranaction and Commit methods. I am calling a stored procedure after BeginTransaction and before Commit.

And the stored procedure returns Ident_Current, should it return the last inserted value in that table or 0?

Thanks, Bhupesh

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
bhupesh
  • 104
  • 9

1 Answers1

2

Warning: Do NOT ever (unless you have a very specific and targeted reason to) use Ident_Current() - use Scope_Identity(). Ident_Current() will return the last Identity value inserted by ANY Session, not just yours.

Scope_Identity() will contain the value you want.

https://learn.microsoft.com/en-us/sql/t-sql/functions/scope-identity-transact-sql

Returns the last identity value inserted into an identity column in the same scope. A scope is a module: a stored procedure, trigger, function, or batch. Therefore, two statements are in the same scope if they are in the same stored procedure, function, or batch.

Rachel Ambler
  • 1,440
  • 12
  • 23
  • Thanks , I will take care of this, but even if I change that to Scope_Identity my question is about the return value, please help me on that. – bhupesh Jun 05 '17 at 20:09
  • 1
    I did: "Scope_Identity() will contain the value you want." – Rachel Ambler Jun 05 '17 at 20:18
  • If my response doesn't jive with you it's more down to your question. "And the stored procedure returns Ident_Current, should it return the last inserted value in that table or 0?" You'd be better served giving us the text of your procedure so we can answer more accurately to your situation. As it is, given the limited information you supplied, it's pretty much the best answer I can give. – Rachel Ambler Jun 05 '17 at 20:41