I am inserting record in a remote Sql Server using Linked server, Now I wanna get the id of inserted record. something like scope_identity()
in local server.
My remote sql server is 2000 version.
I have seen this post but I can't add any stored procedures in remote sql server
Yet another variation, in case linked user has permission to call procedures on linked server:
You could use the remote side's
sp_executesql
:Alternatively, you could use
OPENQUERY
:try something like this:
the EXEC will return a result set containing the
SCOPE_IDENTITY()
valueif you have to do this for SQL Server 2005+ you can just add an
OUTPUT INSERTED.IdentityColumn
to get a result set of the identitie(s). Add anINTO
onto thatOUTPUT
and you can store them in a table/table variable on the local machine.