simple query with params
Moderators: gto, cipto_kh, EgonHugeist
-
- Junior Boarder
- Posts: 26
- Joined: 04.09.2005, 14:46
simple query with params
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
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
-
- Fresh Boarder
- Posts: 20
- Joined: 21.11.2005, 10:13
- Location: Pieštany
- Contact:
-
- Junior Boarder
- Posts: 26
- Joined: 04.09.2005, 14:46
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
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
Quick and dirty: Insert the parameters diractly into SQL, example:
Where LagerVar and VSortVar is your variable. If needed, apply IntToStr, FloatToStr,.. etc.
Code: Select all
dmlager.zquery2.SQL.Clear;
dmlager.ZQuery2.SQL.Add('select * from "T_BUCHUNG" where "LAGERORT" = '+LagerVar+' order by '+VSortVar);
dmlager.ZQuery2.Open;
I got a same error, too! Bellow code does not work correctly!!An error was found in the application program input parameters for the sql statement. The sql: select * from "T_BUCHUNG" where "LAGERORT" = ? order by ?;' . .....
Code: Select all
ZQuery1.ParamByName('USERID').AsString := 'test';
regards
byungho