Tuesday, June 5, 2007

Procedure Call

Procedure calls can be done with parameters. However, for Access 2003 using the keyword "PROCEDURE" creates a 'General SQL error'. Using "PROC" however, does work.

The following example worked in Borland.

str = "CREATE TABLE tblInvoices2 ("
" InvoiceID INTEGER NOT NULL,"
" InvoiceDate DATETIME NOT NULL)";
qry->Execute( str );

str = "INSERT INTO tblInvoices2 VALUES (1, '1/1/1999')";
qry->Execute( str );
str = "INSERT INTO tblInvoices2 VALUES (1, '1/1/1998')";
qry->Execute( str );

str = "CREATE PROC DeleteInvoices2 "
" (InvoiceDate DATETIME) AS "
" DELETE FROM tblInvoices2 "
" WHERE tblInvoices2.InvoiceDate < InvoiceDate ";

// create procedure
qry->Execute( str );

str = "EXECUTE DeleteInvoices2 '1/1/1999' ";
qry->Execute( str );

The final result was that the new table only contained the 1/1/1999 date.

No comments: