Param in Query / Multiple String
Hy, i use Fastreport with Delphi, and in a big query i want to filter the data in a column of type STRING.
The user select multiple string in a CheckListbox in Delphi and i must send this selection for my query is correct.
The User select 3 filters 'A1','B2','B5' in delphi.
My Query :
SELECT * FROM TABLE1 WHERE ACOLUMN1 IN (:PARAM1)
PARAM1 :
Data Type : 'STRING'
Value : <ASELECT> <- My Variable is set in Delphi
But i don't find the syntax for setting correctly 'A1','B2','B5' in my Variable ASELECT in Delphi.
Thank for your Help.
The user select multiple string in a CheckListbox in Delphi and i must send this selection for my query is correct.
The User select 3 filters 'A1','B2','B5' in delphi.
My Query :
SELECT * FROM TABLE1 WHERE ACOLUMN1 IN (:PARAM1)
PARAM1 :
Data Type : 'STRING'
Value : <ASELECT> <- My Variable is set in Delphi
But i don't find the syntax for setting correctly 'A1','B2','B5' in my Variable ASELECT in Delphi.
Thank for your Help.
Comments
I set the Variable Value in Delphi :
Variable.value := '''' + 'A1' + '''' + ',' + '''' + 'B2' + '''' + ',' + '''' + 'B5' + '''';
And When i execute the report, i have an error :
"Error in the Expression ''A1','B2','B5'' : ';' expected".
If someone can help me, or indicate a solution more easy for setting my Variable Value .......
Thank
The number of select is variables.
Or there is not a filter ?
it cannot resolve the where clause parameter portion
WHERE ACOLUMN1 IN (:PARAM1)
what you may have to do is work entirely from delphi and pass the complete sql into
the query object after the report is loaded by using the findobjectmethod and setting the sql prop.
if the query's sqlstring is hard coded it will work. so build the string, add it to the query.
here is a sample change i made in the main demo internalquery report to illustrate.
create a variable mystrvar and give it a value of '"FL","CA"'
cleared the sql prop of the query
var
sqlstr:string; // added global variable
// added procedure for ok button
procedure Button1OnClick(Sender: TfrxComponent);
begin
sqlstr :='select c.* from Customer c where c.State in('+<mystrvar>+')';
//showmessage(sqlstr); this was to check the string
bdequery1.sql.add(sqlstr);
end;
You need to be care full when you set the mystrvar value from delphi
so that the value has begining and ending delimiters
try ''''+quotedstr(value)+','+quotedstr(value)+''''