var
strng,value,UserName : WideString;
Query : Smplquery;
begin
strng := 'table';
value := 'column';
Username := 'CN=ABC[EXT] XYZ, AB=HELLO EFG,AB=SDRTY0045,AB=DW,AB=BNKM,HB=SWCD,HB=4QW,HB=PKL';
Query := CreateSmplquery();
Query.SelectStatement:= format('select * from %s where CONVERT(VARCHAR,%s'+') = (select convert(varchar,%s'+'))',[strng, value, UserName]);
Query.Run;
end;
On compiling this query in the Delphi IDE, an error occurs as this is creating a query as below:
select *
from table
where CONVERT(VARCHAR,column) = (select convert(varchar,thatCN=ABC[EXT] XYZ, AB=HELLO EFG,AB=SDRTY0045,AB=DW,AB=BNKM,HB=SWCD,HB=4QW,HB=PKL))
How to code it so that I get this SQL query instead?
select *
from table
where CONVERT(VARCHAR,column) = (select convert(varchar,'thatCN=ABC[EXT] XYZ, AB=HELLO EFG,AB=SDRTY0045,AB=DW,AB=BNKM,HB=SWCD,HB=4QW,HB=PKL'))
New contributor
Lucas is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
3
You just include the '
in the string. To include a '
character in a string, you need to write it twice, that is ''
. This is how it needs to look:
Query.SelectStatement:= format('select * from %s where CONVERT(VARCHAR,%s'+') = (select convert(varchar,''%s'''+'))',[strng, value, UserName]);
(You could have made a simpler example.)
2