我要查employee表中什麼時間進廠的員工的信息.字段是employee_indate(此字段在sql中定義為datetime類型.)下面意思是我從combobox1中選擇了"入廠日期".之後在edit_search中輸入了入廠時間.如2001/10/24.之後按查詢.
var
  d:tdatetime;
if combobox1.ItemIndex=2 then
  begin
    d:=strtodatetime(edit_search.Text);
    with adoq_rsquery do
    begin
      close;
      sql.Clear;
      sql.Add('select * from employee where employee_indate=''d''');
      open;
    end;
  end;
可是出現"syntax error converting datetime from character string.請問各位應怎樣轉換.

解决方案 »

  1.   

    sql.Add('select * from employee where employee_indate='+d);
      

  2.   

    SQL.Add('select * from employee where employee_indate=' + QuotedStr(FormatDate('yyyy-mm-dd', d)));
      

  3.   

    字段负值错误,如果按照你的写法,那么查询条件就是employ_indate='d'了,
    对于变量应该放到字符串的外面,并且要转化成string形式。
    我觉得楼上老兄说的应该对了
      

  4.   

    也可以用参数:
    adoq_rsquery.sql.Add('select * from employee where employee_indate=:date1);
    adoq_rsquery.parambyname('date1').asdate:=d;
      

  5.   

    SQL.Add('select * from employee where employee_indate=' + ''''+QuotedStr(FormatDate('yyyy-mm-dd', d))+'''');
     
     
    ============================
    @* .☆ / */ . / * . ☆/ *。
       ◢◣。       ◢◣。
      ◢★◣。     ◢★◣。
     ◢■■◣。   ◢■■◣。
    ◢■■■◣。 ◢■■■◣。
    ︸︸||︸︸ !!︸︸||︸︸
    愿您有快乐的每一天 ^_^!!
      

  6.   

    cxz9:
    提示是undeclared identifier "formatdate".
    怎麼回事啊,各位
      

  7.   

    SQL.Add('select * from employee where employee_indate=to_date('+''''+d+''''+')')
      

  8.   

    'select * from employee where employee_indate='+StrToDate(d)+''''
      

  9.   

    不好意思,写错了。
    'select * from employee where employee_indate='+StrToDate(edit_search.Text)+''''
      

  10.   

    SQL.Add('select * from employee where employee_indate=' + ''''+QuotedStr(FormatDate('yyyy-mm-dd', d))+'''');
      

  11.   

    不需要把String轉換為DateTime型 ﹐就直接可以﹕
    sql.Add('select * from employee where employee_indate='+''''+Trim(edit_search.Text)+'''');
    'formatdate'應該是formatDateTime()是一個轉換日期格式的函數。
      

  12.   

    sayforever的可行.也謝謝大家!