用adoconnection,adoquery,datasourse,dbgrid这几个控件,数据库为SQL 2000
想在ADOQUERY1.add中添加如下SQL语句,其中where s.cdt>='2009-01-01' and s.cdt<='2009-01-10' 这里的日期从edit1.txt,edit2.txt中获得。
请问adoquery1.sql.add  语句应该怎么写,试了几次总是不对,请高人指点
select w.csno as SN,w.macno as macAddress,s.model,s.cdt AS Date,c.wcname as TestStation,
      (case s.ispass when 0 then 'FAIL' else 'PASS' end) as [TestResult],
      (case s.ispass when 0 then f.defect else '' end) as [FailCode],
      (case s.ispass when 0 then d.doc else '' end)  as [FailureReason],'' as DefectType,'' as RefDes,'Sercomm' as [ODM]
from sfc_log s with(nolock) 
full join wosn09 w with(nolock)
on w.pcb + w.isno = s.isno
full join wc c with(nolock)
on s.wcno = c.wcno 
full join sfc_dftm d with(nolock)
on s.isno = d.isno 
full join defect f with(nolock)
on d.defect = f.defect 
where s.cdt>='2009-01-01' and s.cdt<='2009-01-10' and w.macno<>''

解决方案 »

  1.   

    var sqlstr:string;
    begin
      sqlstr :='select w.csno as SN,w.macno as macAddress,s.model,s.cdt AS Date,c.wcname as TestStation,  '
              +'  (case s.ispass when 0 then '+Quotedstr('FAIL')+' else '+Quotedstr('PASS')+' end) as [TestResult],  '
              +'  (case s.ispass when 0 then f.defect else '+Quotedstr('')+' end) as [FailCode], '
              +'        (case s.ispass when 0 then d.doc else '+Quotedstr('')+' end)  as [FailureReason],'+Quotedstr('')+' as DefectType,'+Quotedstr('')+' as RefDes,'+Quotedstr('Sercomm')+' as [ODM]  '
              +'  from sfc_log s with(nolock)  '
              +'  full join wosn09 w with(nolock)   '
              +'  on w.pcb + w.isno = s.isno  '
              +'  full join wc c with(nolock) '
              +'  on s.wcno = c.wcno '
              +'  full join sfc_dftm d with(nolock) '
              +'  on s.isno = d.isno  '
              +'  full join defect f with(nolock) '
              +'  on d.defect = f.defect '
              +'  where s.cdt>='+Quotedstr('2009-01-01') +'and s.cdt <='+Quotedstr('2009-01-10')+ 'and w.macno <>'+Quotedstr('');
      with ADOQuery1 do
      begin
        close;
        sql.Clear;
        sql.Add(sqlstr);
        open;
      end;
      

  2.   

    在查询分析器可以运行的那个日期部分是要从edit1.txt和edit2.txt里获得
      

  3.   

    var sqlstr:string; 
    begin 
      sqlstr :='select w.csno as SN,w.macno as macAddress,s.model,s.cdt AS Date,c.wcname as TestStation,  ' 
              +'  (case s.ispass when 0 then '+Quotedstr('FAIL')+' else '+Quotedstr('PASS')+' end) as [TestResult],  ' 
              +'  (case s.ispass when 0 then f.defect else '+Quotedstr('')+' end) as [FailCode], ' 
              +'        (case s.ispass when 0 then d.doc else '+Quotedstr('')+' end)  as [FailureReason],'+Quotedstr('')+' as DefectType,'+Quotedstr('')+' as RefDes,'+Quotedstr('Sercomm')+' as [ODM]  ' 
              +'  from sfc_log s with(nolock)  ' 
              +'  full join wosn09 w with(nolock)  ' 
              +'  on w.pcb + w.isno = s.isno  ' 
              +'  full join wc c with(nolock) ' 
              +'  on s.wcno = c.wcno ' 
              +'  full join sfc_dftm d with(nolock) ' 
              +'  on s.isno = d.isno  ' 
              +'  full join defect f with(nolock) ' 
              +'  on d.defect = f.defect ' 
              +'  where s.cdt>='+Quotedstr(edit1.txt) +'and s.cdt <='+Quotedstr(edit2.txt)+ 'and w.macno <>'+Quotedstr(''); 
      with ADOQuery1 do 
      begin 
        close; 
        sql.Clear; 
        sql.Add(sqlstr); 
        open; 
      end;
      

  4.   

    st:=datetostr(datetimepicker1.date)+' '+FormatDateTime('hh:nn:ss',DateTimePicker2.DateTime);
    et:=datetostr(datetimepicker3.date)+' '+FormatDateTime('hh:nn:ss',DateTimePicker4.DateTime); sqlstr :='select w.csno as SN,w.macno as macAddress,s.model,s.cdt AS Date,c.wcname as TestStation,  ' 
              +'  (case s.ispass when 0 then '+Quotedstr('FAIL')+' else '+Quotedstr('PASS')+' end) as [TestResult],  ' 
              +'  (case s.ispass when 0 then f.defect else '+Quotedstr('')+' end) as [FailCode], ' 
              +'        (case s.ispass when 0 then d.doc else '+Quotedstr('')+' end)  as [FailureReason],'+Quotedstr('')+' as DefectType,'+Quotedstr('')+' as RefDes,'+Quotedstr('Sercomm')+' as [ODM]  ' 
              +'  from sfc_log s with(nolock)  ' 
              +'  full join wosn09 w with(nolock)  ' 
              +'  on w.pcb + w.isno = s.isno  ' 
              +'  full join wc c with(nolock) ' 
              +'  on s.wcno = c.wcno ' 
              +'  full join sfc_dftm d with(nolock) ' 
              +'  on s.isno = d.isno  ' 
              +'  full join defect f with(nolock) ' 
              +'  on d.defect = f.defect ' 
              +'  where s.cdt>='+Quotedstr('st') +'and s.cdt <='+Quotedstr('et')+ 'and w.macno <>'+Quotedstr('');with ADOQuery1 do
    begin
    ADOQuery1.close;
    ADOQuery1.sql.Clear;
    ADOQuery1.sql.Add(sqlstr);
    ADOQuery1.open;
    label4.Caption:='共找到'+inttostr(adoquery1.RecordCount)+'条记录。';
    end;执行的时候总是提示“delphi从字元字串转换到datetime时,转换失败”
    请问WHERE后面的条件该如何修改?
      

  5.   

    st:=datetostr(datetimepicker1.date)+' '+FormatDateTime('hh:mm:ss',DateTimePicker2.DateTime); 
    et:=datetostr(datetimepicker3.date)+' '+FormatDateTime('hh:mm:ss',DateTimePicker4.DateTime); 
    sqlstr :='select w.csno as SN,w.macno as macAddress,s.model,s.cdt AS Date,c.wcname as TestStation,  ' 
              +'  (case s.ispass when 0 then '+Quotedstr('FAIL')+' else '+Quotedstr('PASS')+' end) as [TestResult],  ' 
              +'  (case s.ispass when 0 then f.defect else '+Quotedstr('')+' end) as [FailCode], ' 
              +'        (case s.ispass when 0 then d.doc else '+Quotedstr('')+' end)  as [FailureReason], '+Quotedstr('')+' as DefectType, '+Quotedstr('')+' as RefDes, '+Quotedstr('Sercomm')+' as [ODM]  ' 
              +'  from sfc_log s with(nolock)  ' 
              +'  full join wosn09 w with(nolock)  ' 
              +'  on w.pcb + w.isno = s.isno  ' 
              +'  full join wc c with(nolock) ' 
              +'  on s.wcno = c.wcno ' 
              +'  full join sfc_dftm d with(nolock) ' 
              +'  on s.isno = d.isno  ' 
              +'  full join defect f with(nolock) ' 
              +'  on d.defect = f.defect ' 
              +'  where s.cdt>= '+Quotedstr('st') +' and s.cdt <= '+Quotedstr('et')+ ' and w.macno <>'+Quotedstr(''); with ADOQuery1 do 
    begin 
    ADOQuery1.close; 
    ADOQuery1.sql.Clear; 
    ADOQuery1.sql.Add(sqlstr); 
    ADOQuery1.open; 
    label4.Caption:='共找到'+inttostr(adoquery1.RecordCount)+'条记录。'; 
    end;