Page 1 of 1

simple query with params

Posted: 07.01.2006, 21:22
by Josef Koller
Hello,

I would like to start the following SQL-statement:

dmlager.zquery2.SQL.Clear;
dmlager.ZQuery2.SQL.Add('select * from "T_BUCHUNG" where "LAGERORT" = :vrLager order by :vrsort');
dmlager.ZQuery2.Params[0].AsString:=vrLager;
dmlager.zquery2.params[1].asstring:=vrsort;
dmlager.ZQuery2.Open;

but I get the following error message:

An error was found in the application program input parameters for the sql statement. The sql: select * from "T_BUCHUNG" where "LAGERORT" = ? order by ?;' . .....

vrLager has the value: for example KOLL and vrsort BUCHUNGSDATUM.

Only with the following statement I got a result:

dmlager.zquery2.SQL.Clear;
dmlager.ZQuery2.SQL.Add('select * from "T_BUCHUNG" where "LAGERORT" = ' +qoutedstr(vrLager)+' order by '+quotedstr(vrsort)+'');
//dmlager.ZQuery2.Params[0].AsString:=vrLager;
//dmlager.zquery2.params[1].asstring:=vrsort;
dmlager.ZQuery2.Open;

That's not normal, I think. What's wrong in my first statement?

Many thanks and best regards

Josef

Posted: 09.01.2006, 11:23
by pol
Hello Josef,

You want to pass the column name for your "order by" as a bind variable? I don't think that this is possible.

Best regards,
Rüdiger

Posted: 09.01.2006, 14:16
by designshouse
dmlager.zquery2.SQL.Clear;
dmlager.ZQuery2.SQL.Add('select * from "T_BUCHUNG" where "LAGERORT" = :vrLager order by :vrsort');
dmlager.ZQuery2.ParamByName('vrLarger').AsString:=vrLager;
dmlager.zquery2.ParamByName('vrsort').AsString:=vrsort;
dmlager.ZQuery2.Open;

Posted: 09.01.2006, 17:52
by Josef Koller
Hi,

thanks for answer, but with your statement I get the same error.
The problem is the paramter for the field in the order statement BUCHUNGSDATUM.

At first I thougt that the ' ' are the problem. but I found in the JEDI-Lib a function StrTrimQuotes but I get the errer, too.

I find no way to declare a fieldname with a parameter statement. Only

sql. add('Select * from ..........order by '+:vrSort) works.

Any other ideas?

Kind regards

Josef

Posted: 11.01.2006, 10:53
by zippo
Quick and dirty: Insert the parameters diractly into SQL, example:

Code: Select all

dmlager.zquery2.SQL.Clear;
dmlager.ZQuery2.SQL.Add('select * from "T_BUCHUNG" where "LAGERORT" = '+LagerVar+' order by '+VSortVar);
dmlager.ZQuery2.Open;
Where LagerVar and VSortVar is your variable. If needed, apply IntToStr, FloatToStr,.. etc.

Posted: 19.01.2006, 16:10
by Byungho
An error was found in the application program input parameters for the sql statement. The sql: select * from "T_BUCHUNG" where "LAGERORT" = ? order by ?;' . .....
I got a same error, too! Bellow code does not work correctly!!

Code: Select all

ZQuery1.ParamByName('USERID').AsString := 'test';
My app works on D7 Enterprise and Zeos 6.1.5 with path2

regards
byungho

Posted: 20.01.2006, 09:56
by pol
@Byungho:
What is your SQL?

Regards,
Rüdiger

Posted: 21.01.2006, 18:31
by zippo
I always construct the entire SQL statement by myself and works well... I had similar problems with params in the past, so I switched to "manual"...

Posted: 23.01.2006, 17:00
by Byungho
pol wrote:@Byungho:
What is your SQL?

Regards,
Rüdiger
I use embedded firebird-1.5 , D7 and Zeos 6.1.5!! Windows XP SP2

Posted: 24.01.2006, 09:30
by pol
No, I mean, what is ZQuery1.SQL?