How to get result value from SQL Procedure

Discussion of open issues, suggestions and bugs regarding UniDAC (Universal Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
gmartins
Posts: 4
Joined: Mon 22 Jun 2009 16:41

How to get result value from SQL Procedure

Post by gmartins » Tue 27 Nov 2012 13:13

Hello.
I'm using Unidac 3.50 with delphi 7.
I need to execute a stored procedure in SQL Server and get the returned value (int).
Any tips on how to do this? I tried with Tuniquery and TUniStoredProc with no sucess.
Thanks in advance.

Regards

Goncalo

AndreyZ

Re: How to get result value from SQL Procedure

Post by AndreyZ » Tue 27 Nov 2012 13:53

Hello,

Here is a code example:

Code: Select all

UniStoredProc1.StoredProcName := 'AddInts';
UniStoredProc1.PrepareSQL;
UniStoredProc1.ParamByName('int1').AsInteger := 1;
UniStoredProc1.ParamByName('int2').AsInteger := 3;
UniStoredProc1.Execute;
ShowMessage(IntToStr(UniStoredProc1.ParamByName('res').AsInteger));
, where AddInts is the following stored procedure:

Code: Select all

CREATE PROCEDURE AddInts
@int1 INT,
@int2 INT,
@res INT OUT
AS
BEGIN
  SET @res = @int1 + @int2;
END

Post Reply