Subject | Re: [IBO] How to declare variable in query? |
---|---|
Author | Rafael Colucci |
Post date | 2004-05-19T13:13:35Z |
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
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!09:31:31 -0300:
> You wrote to <IBObjects@yahoogroups.com> on Mon, 19 May 2003
>equal!)
> 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
> // 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 orInterBase
> without the need for BDE, ODBC or any other layer.___________________________________________________________________________
>
> http://www.ibobjects.com - your IBO community resource for Tech Infopapers,
> keyword-searchable FAQ, community code contributions and more !
> Yahoo! Groups Links
>
>
>
>