Subject Re: [IBO] How to declare variable in query?
Author Rafael Colucci
Hi

No .. is not this. I need to do in query ... like this:

DECLARE varCount integer;
begin
SELECT Count(*) FROM Conta WHERE NomeConta = 'gugu' into varcount;
if (varCount <= 0) then
INSERT INTO Conta (NomeConta,IsAtiva) VALUES ('gugu', 1);

This query works if I put in stored procedure, but not work if i put like:

Ib_Query.sql.text :=
DECLARE varCount integer;
begin
SELECT Count(*) FROM Conta WHERE NomeConta = 'gugu' into varcount;
if (varCount <= 0) then
INSERT INTO Conta (NomeConta,IsAtiva) VALUES ('gugu', 1);

Rafael

> Hello, Rafael!
> You wrote to <IBObjects@yahoogroups.com> on Mon, 19 May 2003
09:31:31 -0300:
>
> RC> I dont´t know how to use variables in querys, without use stored
> RC> procedure and triggers...
> RC> The command declare variable don´t works in single querys ...
> RC> Anybody can show me a example?
>
> Simple example:
>
> var Q:TIB_Query;
> T:TIB_Transaction;
> begin
> T:=TIB_Transaction.Create(Self);
> try
> Q:=TIB_Query.Create(Self);
> try
> Q.IB_Transaction:=T;
> T.IB_Connection:=My_IB_Connection_Here;
> Q.IB_Connection:=T.IB_Connection;
> T.StartTransaction;
> with Q do
> begin
> close; sql.clear; //- if query Q used previos in another place of
> code
> // -- fill query SQL
> sql.text:='UPDATE MyTable SET MyField=?NewValue WHERE
> MyField=?OldValue';
> Prepare; // -- must be for get access to parameters
> // set parameters
> ParamValues['NewValue'] := 12345; // way 1
> ParamByName('OldValue').AsInteger:= 45678; // way 2 (ways are
equal!)
> // execute query
> Execute; Close;
> end;
> T.Commit;
> T.Close;
> finally Q.Free; end;
> finally T.Free; end;
> end;
>
>
> WBR, Dmitry Beloshistov AKA [-=BDS=-]
>
>
>
>
___________________________________________________________________________
> IB Objects - direct, complete, custom connectivity to Firebird or
InterBase
> without the need for BDE, ODBC or any other layer.
>
___________________________________________________________________________
> http://www.ibobjects.com - your IBO community resource for Tech Info
papers,
> keyword-searchable FAQ, community code contributions and more !
> Yahoo! Groups Links
>
>
>
>