Board index » delphi » Passing parameters to stored procedure.

Passing parameters to stored procedure.


Using Delphi 4 and SQL Server 7.

There are several ways to pass parameters to a stored procedure.
- The standard way using stored procedure parameters but is only usefull for
single parameters;
- Creating a table on the database and so we can fill that table with
records but another users have access to that same table;
- Creating a table like the above but this table being temporary (for
example #temp) but if in the same application if I have multi-instance
forms, when opening a second form it gives me an error (obviously)

I would like to know if there is another alternative, that I can use to pass
multiply parameters (as a table) but that will work on multi-user and
multi-instance applications.

   Fernando J.A. Silva (aka ^Magico^)


Re:Passing parameters to stored procedure.

Hi Fernando,

what do you think about direct SQL? I only work with direct SQL commands. Then
you can run a stored proc like you would type it in an isql-program:

with DataModule1 do begin
  with Query1.SQL do begin
    Add('SELECT TableA.XXX1, TableA.XXX2, TableB.YYY1');
    Add('FROM TableA');
    Add('INNER JOIN TableB ON TableB.X1=TableA.X1');
    Query1.Open;  // use "Query1.ExecSQL" if your SQL-command
                  // does not result in a query (e.g. if it is
                  // a "UPDATE Table...")
    on E:Exception do begin
      WriteErrorToLogFile('Command XYZ failed. SQL-Server-Message='+E.Message);
      raise Exception.Create(E.Message);

Instead of this SELECT-command above you can execute a stored procedure. I think
the SQL-command for that is "EXECUTE {ProcName} {Param1}, {Param2}...", but I'm
not sure on that. Take a look in the documentation of your SQL-server...

Hope, that helped you!

Bye, Marco ;-)

Other Threads