我在delphi中编写了一个带有参数的SQL查询
WHERE L1.IdListino = :IdListino
根据用户的一些输入,我希望此参数可以是表单的字段(tParsIdListinoExport 是字段的名称),也可以是另一个表的列(类似于 WHERE L1.IdListino = fat.IdListino )。
if tParsIdListinoExport.AsString <> '' then
qSel.ParamByName( 'IdListino' ).AsString := tParsIdListinoExport.AsString
else
qSel.ParamByName( 'IdListino' ).Value := 'fat.IdListino';
end;
遗憾的是,看起来我无法插入列名称作为参数,因为它在列名称周围添加了“”,从而将其视为纯文本。 是否可以从参数中删除“”? 非常感谢,
法比奥
最佳答案
您需要在运行时创建 SQL 指令,例如:
with qSel do
begin
Close;
SQL.Clear;
SQL.Add(addYourSqlHere, without Where clause);
if Condition1 then
SQL.Add('where FIELD1 = :PARAM01')
else
SQL.Add('where FIELD2 = :PARAM01');
ParamByName('PARAM01').Value := UserFilter;
end;
关于sql - 在 Delphi SQL 参数中插入字段名称而不是字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42769317/