sql语句中,类型不匹配

guoke888 2003-05-04 05:34:10
1、sql.Add('select n_je from c_ysr where c_xm='''+cbx_srz.Text+''' and n_yf='''+s+''' ');
2、sql.Add('select n_je from c_ysr where c_xm='''+cbx_srz.Text+''' and n_yf=''s'' ');
字段n_yf是日期类型,s是字符串,上面两个sql语句都不对,都是标准表达式类型不匹配。
如何在sql中,如何查找日期类型的字段呢?
...全文
86 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
guoke888 2003-05-04
  • 打赏
  • 举报
回复
感谢金子 后面的我没测试, 不过酌情给分
wangshenwang1 2003-05-04
  • 打赏
  • 举报
回复
var s:string;
begin
s:=FormatDateTime('YYYY-MM-DD',Edit1.Text);
ADOQuery1.close;
ADOQuery1.SQL.Clear;
ADOQuery1.SQL.Add('select * from rsgzmx where rq='''+s+'''');
ADOQuery1.Open;
//rq为日期型字段
end;
iwstudy 2003-05-04
  • 打赏
  • 举报
回复
将字符串中的字符按日期格式存放比如2003-05-04
wangshenwang1 2003-05-04
  • 打赏
  • 举报
回复
ADOQuery1.close;
ADOQuery1.SQL.Clear;
ADOQuery1.SQL.Add('select * from rsgzmx where rq='''+Edit1.Text+'''');
ADOQuery1.Open;
rq为日期型字段
csouth 2003-05-04
  • 打赏
  • 举报
回复
把S的值show出来看看,是不是合格的日期型呀
csouth 2003-05-04
  • 打赏
  • 举报
回复
sql.Add('select n_je from c_ysr where c_xm='''+cbx_srz.Text+''' and n_yf=#'+s+'# ');
guoke888 2003-05-04
  • 打赏
  • 举报
回复
楼上的我实验过了,parambyname 没定义,我用的是adoquery控件,
wangshenwang1 2003-05-04
  • 打赏
  • 举报
回复
p1 := datetostr(DateTimePicker1.date);
query14.close;
query14.sql.clear;
query14.sql.add('select n_je from c_ysr where c_xm='''+cbx_srz.Text+
''' and n_yf=:n_yf1');
query14.ParamByName('n_yf1').asdatetime := strtodate(p1);
query14.Prepare;
query14.open;
guoke888 2003-05-04
  • 打赏
  • 举报
回复
使用的access数据库
guoke888 2003-05-04
  • 打赏
  • 举报
回复
还是不对啊
飞天林 2003-05-04
  • 打赏
  • 举报
回复
sql.Add('select n_je from c_ysr where c_xm='''+cbx_srz.Text+''' and n_yf='''+FormatDateTime('YYYY-MM-DD HH:MM:SS',StrToDateTime(s))+''' ');
可能是s字符串的格式不是日期格式的
guoke888 2003-05-04
  • 打赏
  • 举报
回复
依然如此,字段c-xm是文本 n_yf是日期类型
pingshx 2003-05-04
  • 打赏
  • 举报
回复
sql.Add('select n_je from c_ysr where c_xm="'+cbx_srz.Text+'"'+ 'and'
+ 'n_yf=to_date('+s+','''yyyy-mm-dd''');
这是在oracle,用数据库函数!
hawkoffree 2003-05-04
  • 打赏
  • 举报
回复
改成如下格式应该没问题:
1、sql.Add('select n_je from c_ysr where c_xm="'+cbx_srz.Text+'"'+ 'and'
+ 'n_yf="'+s+'"');

5,388

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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