Je zou de sp_executesql
. van de externe kant kunnen gebruiken :
DECLARE @ScopeIdentity TABLE (ID int);
INSERT INTO @ScopeIdentity
EXEC server.master..sp_executesql N'
INSERT INTO database.schema.table (columns) VALUES (values);
SELECT SCOPE_IDENTITY()';
SELECT * FROM @ScopeIdentity;
Als alternatief kunt u OPENQUERY
. gebruiken :
SELECT *
FROM OPENQUERY(server, '
INSERT INTO database.schema.table (columns) VALUES (values);
SELECT SCOPE_IDENTITY() AS ID');