update [myCounter] set [counter] = [counter] + 1;>
-- Procedure NextID create procedure [dbo].[NextId] @tableName varchar(200), @start int output, @end int output, @nRows int = 1 as begin set nocount on update ids set nextID = nextID + @nRows where tableName = upper(@tableName) ; if @@rowcount = 0 begin insert into ids ( tableName, nextID ) values ( upper(@tableName), @nRows ) ; end select @start = nextID - @nRows + 1, @end = nextID from ids where tableName = @tableName ; --nextId is last ID used --nRows IDs are allocated for the caller endAnd VFP GetNextID procedure code:
*GetNextID.prg Lparameters tcTableName, tnCount Local loConn as 'ADODB.Connection',loCommand as 'ADODb.Command',loRS as 'ADODb.RecordSet',lnReturn loConn = Createobject('ADODB.Connection') loCommand = Createobject('ADODB.Command') loConn.ConnectionString = oApp.ADODataConnectionString loConn.Open loCommand.ActiveConnection = loConn loCommand.CommandType = 4 && stored procedure Do Case Case oApp.DataMode == 'SQL' loCommand.CommandText = 'NextID' loCommand.Parameters.Refresh loCommand.Parameters('@tableName').Value = m.tcTableName loCommand.Parameters('@nRows').Value = EVL(m.tnCount,1) loCommand.Execute lnReturn = loCommand.Parameters('@end').Value Case oApp.DataMode == 'VFP' loCommand.CommandText = Textmerge('NextID("<<m.tcTableName>>",<<EVL(m.tnCount,1)>>)') loRS = loCommand.Execute lnReturn = loRS.Fields(0).Value loRS.Close Endcase loConn.Close Return m.lnReturnoApp is a custom object that keeps current data mode, connection string ... Getting with N > 1 is useful for block insertions.