Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

T-Sql @@Identity

Tags:

tsql

identity

Does someone know how can I return the @@Identity when using T-Sql?

Something like this:

set @Sql = "insert into table....values()..."
exec @sql
return @@Identity
like image 820
Itay.B Avatar asked Sep 13 '10 12:09

Itay.B


1 Answers

It looks like one of your implicit requirements is the execution of dynamic SQL. While I'd advise against this, you can accomplish what you're looking for with this:

set @Sql = 'insert into table....values()...; select SCOPE_IDENTITY()'
exec(@Sql)
like image 107
Ken Avatar answered Oct 14 '22 09:10

Ken