求助--在线等----从字元字串转换到datetime时,转换失败

feiaizhong 2009-02-24 02:07:28
var
st: string;
et: String;



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;


执行的时候总是提示“从字元字串转换到datetime时,转换失败”
请问WHERE后面的条件该如何修改?
...全文
168 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
feiaizhong 2009-02-24
  • 打赏
  • 举报
回复
明白,已经搞定了,谢谢楼上的朋友们!
bdmh 2009-02-24
  • 打赏
  • 举报
回复
如果s.cdt是日期型字段,那就不用加引号了
'  where s.cdt>='+st+' and s.cdt <='+et+ 'and w.macno <>'+Quotedstr(''); 
bdmh 2009-02-24
  • 打赏
  • 举报
回复
ST,ET是变量,就不要再加引号了
starluck 2009-02-24
  • 打赏
  • 举报
回复


var
st: string;
et: String;


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;




starluck 2009-02-24
  • 打赏
  • 举报
回复


var
st: string;
et: String;


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;

2,498

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 数据库相关
社区管理员
  • 数据库相关社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧