Page 1 of 1

paramters and like

Posted: Thu 15 Nov 2012 00:13
by ccmcbride
I'm trying to build this query, but it's not working:
Using sDac 6.5.9, delphi XE, windows 7
if (SearchString <> '') then
begin
gQuery.SQL.Add('select name,uid');
gQuery.SQL.Add('from cust');
gQuery.SQL.Add('where IsActive =''true'' and name like ''%:sString%''');
gQuery.SQL.Add('order by Name');
gQuery.ParamByName('sString').AsString := SearchString;---error, parameter not found


Is my query bad, or is it the 'like' part of it?

Re: paramters and like

Posted: Thu 15 Nov 2012 10:05
by AndreyZ
Hello,

You are using parameters in the wrong way. Your SQL code does not contain the sString parameter, it contains the '%:sString%' constant string. Here is a correct code:

Code: Select all

if (SearchString <> '') then
begin
  gQuery.SQL.Add('select name,uid');
  gQuery.SQL.Add('from cust');
  gQuery.SQL.Add('where IsActive =''true'' and name like :sString');
  gQuery.SQL.Add('order by Name');
  gQuery.ParamByName('sString').AsString := '%' + SearchString + '%';

Re: paramters and like

Posted: Thu 15 Nov 2012 16:37
by ccmcbride
ty. I think I figured that out at about 2 am thie morning in my sleep,when it came together.

Re: paramters and like

Posted: Thu 15 Nov 2012 16:49
by AndreyZ
If any other questions come up, please contact us.