Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Flock equivalent in SQL
Message
De
27/08/2009 07:07:14
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
 
 
À
26/08/2009 19:22:50
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Versions des environnements
Visual FoxPro:
VFP 9 SP1
Database:
MS SQL Server
Divers
Thread ID:
01420778
Message ID:
01421130
Vues:
70
This message has been marked as a message which has helped to the initial question of the thread.
>>I use the follow code to get Unique Keys with VFP tables
>>
>>Local lgetUniqueKey
>>Use myCounter
>>IF Flock()
>> Replace myCounter.counter With myCounter.counter+1
>> lgetUniqueKey= myCounter.counter
>> Flush In myCounter Force
>> Unlock
>>Endif
>>
>>Could you suggest some equivalent code if the MyCounter table is an MSSQL table?
>>Please no autoinc field or global unique identifiers
>
>
update [myCounter] set [counter] = [counter] + 1;
>
>Cetin

Yiorgos,
Though your question's answer is simple as above if you want a more flexible approach here is one of my NextId SP that could allocate a single id (default) or multiple as a block:
-- 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
    end
And 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.lnReturn
oApp is a custom object that keeps current data mode, connection string ... Getting with N > 1 is useful for block insertions.

Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform