Page 1 of 1

Filter in a SQL

Posted: 02.03.2012, 11:40
by jpnuage
Hi folks, spring is coming soon....problems too :(

Please look at the following code.
for i := 1 to Length(Edit.Text) do begin

if Edit1.Text <> '' then
begin
xCode := RightStr(trim(Edit1.Text),5);
ClientDataSet2.Active := false;
ClientDataSet2.ParamByName('CodeArticle').AsString := xCode;
ClientDataSet2.Active := true;
ClientDataSet2.Refresh;

ch := CleEntete; // <--result of previous SQL ClientDataSet2
// looks like 1451,1568,1788,1888
// and may be more numbers
if ch = 'null' then
CDS.Filter := 'ID_ENTETE is null'
else
CDS.Filter := 'ID_ENTETE in (' + ch + ')' ;
CDS.Filtered := true;
CDS.Refresh;
end;
...... //<== rest of code
ID_ENTETE id an Integer.

I get the error message at execution :
Syntax error near in
I tried to replace 'ID_ENTETE in (' + ch + ')' by 'ID_ENTETE is in (1245,1266,1278)' just to see. Same message.

And I cannot work with the adding of filters in the SQL of CDS :wallb:

What is my code miswriting ?

Thank you for any help

Posted: 27.07.2012, 18:33
by josimarz
Hello jpnuage,

Try use the OR operator:

Code: Select all

ID_ENTETE = 1245 OR ID_ENTETE = 1266 OR ID_ENTETE =1278
More about filters:

http://zeos.firmos.at/viewtopic.php?t=3 ... ght=filter

Josimar.

Posted: 28.07.2012, 05:22
by Pitfiend
Which is the SQL engine you are using?
I use filters against MySQL without troubles, but only for strings using quotedstr() function around variables, never tried integers or anything else.
Did you try that instruction in an interactive client first?