例如:
procedure TForm1.Button1Click(Sender: TObject);
var Sql_Str:string;
begin
Sql_Str:='select a.a,a.b from a where a.b in(';
Sql_Str:=Sql_Str+'select b.b from b where b.c=1)';
adoquery1.SQL.Clear;
adoquery1.SQL.add(Sql_Str);
adoquery1.Open;
end;
如何在字符串中增加用户自定义的条件???
例如上面:sql_str:=sql_str+'select b.b from b where b.c=1 and b.d=+''''dblookupcombobox1.text+'''' )';
请问上面这样写行吗??我尝试过,通不过啊????
因为上面的语句中字符串包含一对括号,而我的这个用户所定义的条件一定要在括号内,所以一定要这样写,请问改如何解决?????
procedure TForm1.Button1Click(Sender: TObject);
var Sql_Str:string;
begin
Sql_Str:='select a.a,a.b from a where a.b in(';
Sql_Str:=Sql_Str+'select b.b from b where b.c=1)';
adoquery1.SQL.Clear;
adoquery1.SQL.add(Sql_Str);
adoquery1.Open;
end;
如何在字符串中增加用户自定义的条件???
例如上面:sql_str:=sql_str+'select b.b from b where b.c=1 and b.d=+''''dblookupcombobox1.text+'''' )';
请问上面这样写行吗??我尝试过,通不过啊????
因为上面的语句中字符串包含一对括号,而我的这个用户所定义的条件一定要在括号内,所以一定要这样写,请问改如何解决?????
'''dblookupcombobox1.text'''+' )';
sql_str:=sql_str+'select b.b from b where b.c=1 and b.d='''+dblookupcombobox1.text+'''' )';
Sql_Str := Format('select a.a,a.b from a '
+ 'where a.b in(select b.b from b where b.c=1) and b.d= ''%s'''
, [dblookupcombobox1.text]);
//(Format还有好多用法可以看看帮助。)