Page 1 of 1

Using macro or param

Posted: Fri 23 Apr 2010 10:33
by cybsistemas
CREATE TABLE Customers (
Id smallint(5) unsigned NOT NULL AUTO_INCREMENT,
Name char(40) DEFAULT NULL,
Comision float(12,2) DEFAULT NULL,
PRIMARY KEY (Id)
) ENGINE=MyISAM AUTO_INCREMENT=91 DEFAULT CHARSET=latin1


MyQuery1.SQL.Text := 'select * from Customers where id in (:num);';
MyQuery1.ParamByName('num').AsString := '125,188,225,216';
MyQuery1.Execute;

Error in result



MyQuery1.SQL.Text := 'select * from Customers where id in (&num);';
MyQuery1.MacroByName('num').AsString := '125,188,225,216';
MyQuery1.Execute;

Error in result

As is it done?

Posted: Fri 23 Apr 2010 14:09
by swierzbicki
That is designed as is. You can't pass a string as "list". When you are using .AsString, you are just sending a String. Delphi will replace it :

MyQuery1.SQL.Text := 'select * from Customers where id in (:num);';
MyQuery1.ParamByName('num').AsString := '125,188,225,216';

will be executed like this :
select * from Customers where id in ('125,188,225,216')
instead of
select * from Customers where id in (125,188,225,216)

Try to use macros:

MyQuery1.SQL.Text := 'select * from Customers where id in (&num);';
MyQuery1.MacroByName('num').Vaule := '125,188,225,216';

Posted: Fri 23 Apr 2010 19:06
by cybsistemas
Thanks