求助--在线等----从字元字串转换到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后面的条件该如何修改?
...全文
169 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;

SQL语法大全 SQL语法大全 1. ASP与Access数据库连接: 2. ASP与SQL数据库连接: 建立记录集对象: set rs=server.createobject("adodb.recordset") rs.open SQL语句,conn,3,2 3. SQL常用命令使用方法: (1) 数据记录筛选: sql="select * from 数据表 where 段名=段值 order by 段名 [desc]" sql="select * from 数据表 where 段名 like \'%段值%\' order by 段名 [desc]" sql="select top 10 * from 数据表 where 段名 order by 段名 [desc]" sql="select * from 数据表 where 段名 in (\'值1\',\'值2\',\'值3\')" sql="select * from 数据表 where 段名 between 值1 and 值2" (2) 更新数据记录: sql="update 数据表 set 段名=段值 where 条件表达式" sql="update 数据表 set 段1=值1,段2=值2 …… 段n=值n where 条件表达式" (3) 删除数据记录: sql="delete from 数据表 where 条件表达式" sql="delete from 数据表" (将数据表所有记录删除) (4) 添加数据记录: sql="insert into 数据表 (段1,段2,段3 …) values (值1,值2,值3 …)" sql="insert into 目标数据表 select * from 源数据表" (把源数据表的记录添加到目标数据表) (5) 数据记录统计函数: AVG(段名) 得出一个表格栏平均值 COUNT(*|段名) 对数据行数的统计或对某一栏有值的数据行数统计 MAX(段名) 取得一个表格栏最大的值 MIN(段名) 取得一个表格栏最小的值 SUM(段名) 把数据栏的值相加 引用以上函数的方法: sql="select sum(段名) as 别名 from 数据表 where 条件表达式" set rs=conn.excute(sql) 用 rs("别名") 获取统的计值,其它函数运用同上。 (5) 数据表的建立和删除: CREATE TABLE 数据表名称(段1 类型1(长度),段2 类型2(长度) …… ) 例:CREATE TABLE tab01(name varchar(50),datetime default now()) DROP TABLE 数据表名称 (永久性删除一个数据表) 4. 记录集对象的方法: rs.movenext 将记录指针从当前的位置向下移一行 rs.moveprevious 将记录指针从当前的位置向上移一行 rs.movefirst 将记录指针移到数据表第一行 rs.movelast 将记录指针移到数据表最后一行 rs.absoluteposition=N 将记录指针移到数据表第N行 rs.absolutepage=N 将记录指针移到第N页的第一行 rs.pagesize=N 设置每页为N条记录 rs.pagecount 根据 pagesize 的设置返回总页数 rs.recordcount 返回记录总数 rs.bof

2,499

社区成员

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

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