Search code examples
stored-proceduresvisual-foxpro

how to write stored procedure in Visual Fox Pro


I have a Visual Foxpro Datbase and i am not a programmer of VFP, i have to add a stored procedure, i know where to add stored procedure but i don,t know the syntax for writing simple stored procedure.

if any one help me create a stored procedure which just returns max value of some field from some table, it will help me get on right track. B

 USE mydb;
GO
CREATE PROCEDURE getmax 

AS 

    SET NOCOUNT ON;
  select max(id) from mytable

end

Above is sample stored procedure in SQL version

Thanks


Solution

  • When you enter these lines in Command window:

    Open Database YourDBCName
    Modify Procedure
    

    A code window pops up. That is where you would write your SP code. For example with tableName and fieldName as parameters you could write as:

    Function GetMax( tcTableName, tcFieldName )
        Local Array laMax[1]
        Select Max( &tcFieldName ) ;
            from (m.tcTableName) ;
            into Array laMax
        Return laMax[1]
    Endfunc
    

    You could then say for example:

    result = GetMax( 'Contacts', 'LastName' )
    

    PS: Didn't translate your SP sample because it was wrong already.