Subject Re: [IBO] How to declare variable in query?
Author Dmitry Beloshistov
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=-]