scope_identity

  • Hi

    I have an app in Gupta (Centura) working throu ODBC to SQL2000.

    Currently works with the ident_current ('xxx') function to retrieve the last ID inserted to table 'xxx'.

    I want to change it to scope_identity(), but it returns null.

    The @@identity also works fine.

    Any idea why this happening?

    Thanks a lot

  • This was removed by the editor as SPAM

  • I've never experienced this problem, although I connect through OLEDB rather than ODBC.

    The approach I tend to take is to either put the insert into a stored procedure eg:

    create procedure spInsertData @data nvarchar(20) as

    declare @return int

    insert into mytable(data) values (@Data)

    select @return=scope_identity()

    return @return

    Or alternatively (but technically slower) just execute the insert and select scope_identity() as a single batch

  • I think that throu OLEDB there would be no problem to retrieve scope_identity().

    The store procedure would be a solution but it will be my last choice, because it has to be changed in about 10 places in my code.

    Thanks for your ideas.

Viewing 4 posts - 1 through 3 (of 3 total)

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