When I call SCOPE_IDENTITY in Sybase, I get

[Error] Script lines: 1-6 -------------------------- Function 'SCOPE_IDENTITY' not found. If this is a SQLJ function or SQL function, use sp_help to check whether the object exists (sp_help may produce a large amount of output). Msg: 14216, Level: 16, State: 1 Server: DGTSYBASEDEV101, Line: 3

This is my code:

values ("464545454", "asdd", "AUS",getdate(),getdate())

The SCOPE_IDENTITY function is not available in Sybase ASE as it is specific to Microsoft Sql Server. If you want to obtain the last identity value that was generated you can use the @@IDENTITY global variable like so:

insert into sales_daily (syb_identity, stor_id) 
     values (102, "1349")
select @@identity

You can find the documentation for the @@IDENTITY global variable at SyBooks Online.

  • Ok, I think I misread the documentation. I interpreted this page to mean that Sybase does support scope_identity, but now that I take a closer look at the page, I think this page is outraded/not relevant. infocenter.sybase.com/help/index.jsp?topic=/… Indeed, that page is referring to datawindow.net, whatever that is. – JRG Dec 21 '18 at 0:00
  • Quite possibly as SAP have now bought Sybase so the documentation may not be getting kept up to date on that site. I did notice that near the top it says Applies to SNC SQL Native Client for Microsoft SQL Server though – World Wide DBA Dec 21 '18 at 0:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.