Scope_identity on linked server

  • Morning all,

    Was wondering if it is possible to return the last inserted identity value for a query which inserts into a table on a linked server.

    I have a table on local\sqlexpress ...

    CREATE TABLE [dbo].[JM](

    [col1] [int] IDENTITY(1,1) NOT NULL

    )

    if i login to local and try the following

    insert into [.\sqlexpress].adventureWorks.dbo.JM default values

    select scope_identity()

    It returns null. Is there another function i could use to get round this?

  • I had a similar issue a while back, and found the easiest way to get round it was to wrap the query up in a stored procedure that I executed on the linked server, and return the id as a parameter.

    There may be other ways, but i've never found them!

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply