Thursday, December 2, 2010

Getting newly generated ID auto-number values from Intersystems Cache table, by using ODBC connection provider

In Cache you need to create following Stored Procedure

===========================================================
ClassMethod MaxID(TableName as %String) As %String [ SqlProc ]
{
lastID="0"
lock +(^lastID)
//s cmd1="s ^lastID=^Sample.PersonD"
cmd1="s ^lastID=^"_TableName_"D"
XECUTE cmd1
lastID=^lastID
lock -(^lastID)
lastID

}
===========================================================

In SQL you can access it by using following SQL statement

===========================================================
Select top 1 Sample.Person_MaxID('Sample.Person') AS MaxID from Sample.Person
===========================================================



1 comment:

  1. Superbbbb....
    I m looking for that solution from almost a year.
    thanks

    ReplyDelete

Followers

Search This Blog