数据库是access ,请问我这条sql 语句怎么行不通呢?
Var
Sql_Str:String;
D1,D2:TDateTime;
begin
D1:=DBeginDate.DateTime ;
D2:=EEndDate.DateTime;
Sql_Str:='Select Code_id Code_Type ,Frim_id , Pro_Name from BaseInfo
Where Apply_Date between :D1 and :D2 ';
if Trim(CodeN.Text)<>'' then
Sql_Str:=Sql_Str+' and Code_id like ''%'+CodeN.Text+'%''';
if Trim(CodeType.Text)<>'' then
Sql_Str:=Sql_Str+' and Code_Type like ''%'+CodeType.Text+'%''';
if Trim(CorPoration.Text)<>'' then
Sql_Str:=Sql_Str+' and CorPoration like ''%'+CorPoration.Text+'%''';
if Trim(FrimEdt.Text)<>'' then
Sql_Str:=Sql_Str+' and Frim_id Like ''%'+FrimEdt.Text+'%''';
Sql_Str:=Sql_Str+' order by Code_id ';
With DM.InsertInfoQue do
begin
Close;
Sql.Clear;
Sql.Add(Sql_Str);
Parameters.ParamByName('D1').Value:=Min(D1, D2);
Parameters.ParamByName('D2').Value:=Max(D1, D2);
Open;
end;
Var
Sql_Str:String;
D1,D2:TDateTime;
begin
D1:=DBeginDate.DateTime ;
D2:=EEndDate.DateTime;
Sql_Str:='Select Code_id Code_Type ,Frim_id , Pro_Name from BaseInfo
Where Apply_Date between :D1 and :D2 ';
if Trim(CodeN.Text)<>'' then
Sql_Str:=Sql_Str+' and Code_id like ''%'+CodeN.Text+'%''';
if Trim(CodeType.Text)<>'' then
Sql_Str:=Sql_Str+' and Code_Type like ''%'+CodeType.Text+'%''';
if Trim(CorPoration.Text)<>'' then
Sql_Str:=Sql_Str+' and CorPoration like ''%'+CorPoration.Text+'%''';
if Trim(FrimEdt.Text)<>'' then
Sql_Str:=Sql_Str+' and Frim_id Like ''%'+FrimEdt.Text+'%''';
Sql_Str:=Sql_Str+' order by Code_id ';
With DM.InsertInfoQue do
begin
Close;
Sql.Clear;
Sql.Add(Sql_Str);
Parameters.ParamByName('D1').Value:=Min(D1, D2);
Parameters.ParamByName('D2').Value:=Max(D1, D2);
Open;
end;
解决方案 »
- 怎样在dbgrid里面放单选按钮
- 如何将自定义类写如文件?
- 关于ListBox的问题
- #######Socket的Time_Wait问题,帮顶有分,路过有分,解决了另开贴送分,:)######
- 厦门的delphi程序员们进来吧
- 用过InterBase的来帮忙看看
- 请问如何将字符串'20030303'用DateTimePicker显示啊?谢谢啊~~~在线!
- 用mapinfo ,在delphi中装什么控件来调用?
- 关于delphi6中的Demos\Corba\Idl2Pas\Midas XML例子
- 各位,有谁知道怎么在分辨率改变的时候改变控件的位置,分数送上!
- 各位大虾:求助啊!关于Timer的使用!
- delphi能开发后台是UNIX,数据库是ORICLE的应用程序吗
第二:试试将apply_date between :d1 and :d2 改为 apply_date>=:d1 and apply_date<=:d2。 或者将between放到语句的最后。
仔细看一下Sql_Str就很清楚了
{...}
Parameters.ParamByName('CodeVar').Value := '%'+trim(CodeN.Text)+'%';(注:Like句也写成参数方式)
{...}
Parameters.Clear;
Parameters.AddParameter.Name := 'D1';
Parameters.AddParameter.Name := 'D2';
Parameters.ParamByName('D1').DataType := ftTime; //定義類型試試
Parameters.ParamByName('D2').DataType := ftTime;
{...}
end;
为什么要这样做呢?