adoquery2.Close;        adoquery2.SQL.Clear;
        adoquery2.SQL.Add('select * from employee where room=:room1 and dism_date=''');
        adoquery2.Parameters.parambyname('room1').Value:=adoquery1.Fields[0].AsString;
        if not adoquery2.Prepared then adoquery2.Prepared:=true;
        adoquery2.Open;
錯誤:unclosed quotation  before the character string
下面這條語句出錯:
adoquery2.SQL.Add('select * from employee where room=:room1 and dism_date=''');
dism_date 是datetime類型
這條語句怎麼寫?

解决方案 »

  1.   

    adoquery2.SQL.Add('select * from employee where room = '
    +chr(39)+room1+chr(39)+' and dism_date='+chr(39)+''+chr(39)+');
      

  2.   

    Datetime类型只要不为空值就是日期格式了,你用isnull(dism_date,'')=''试试
      

  3.   

    adoquery2.SQL.Add('select * from employee where room=:room1 and dism_date=''''');
      

  4.   

    楼上的兄差不多.我感觉楼主的语句太繁.可以试一下:
     adoquery2.sql.add('select * from employee where dism_date=isnull(dism_date,'')')
       adoquery1.fields[0].asstring这一句只是获得第一个字段值.似乎没有什么意义             
      

  5.   

    楼主是不是就想要查找dism_date为空得记录
      

  6.   

    如果是这样得语句肯定没有问题
    procedure TForm1.Button1Click(Sender: TObject);
    var
       room1:string;
    begin
          adoquery2.Close;
          adoquery2.SQL.Clear;
          adoquery2.SQL.Add('select * from employee where room=:room1 and dism_date is Null');
          adoquery2.Parameters.parambyname('room1').Value:=adoquery1.Fields[0].AsString;
         if not adoquery2.Prepared then adoquery2.Prepared:=true;
          adoquery2.Open;
          showmessage(inttostr(adoquery2.RecordCount));end;
      

  7.   

    var
       room1:string;这一句你不用管,我是调试程序时用了一下