如何对access中日期进行比较查询?

banban1982 2004-06-16 01:04:08
现在我再vb中用了sql查询
str = " select * from bym where " + Combo1.Text + Combo2.Text + Text1.Text

其中combo1.text是日期(字段名),combo2.text是>,=,<中的1个,text1.text是输入的日期
怎么进行比较?日期格式好像不大对!sql语句那里错了么?
...全文
716 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
online 2004-06-16
  • 打赏
  • 举报
回复
strsql = "select * from test where sj >= # 2004-04-01 # and sj<= # 2004-06-24 #"
这样查询有没有数据啊????
饮水需思源 2004-06-16
  • 打赏
  • 举报
回复
'这样试试:
strsql = "select * from bym where " & Combo1.Text & " " & Combo2.Text & " # " & format(Text1.Text,"YYYY-MM-DD") & "#"
banban1982 2004-06-16
  • 打赏
  • 举报
回复
解决了,不好意思,是我笔误了
banban1982 2004-06-16
  • 打赏
  • 举报
回复
日期
1995-6-3
1995-6-5
1995-6-6
1995-6-9
数据库中有这几个记录,可是我按照你们给的strsql = "select * from bym where " & Combo1.Text & " " & Combo2.Text & " # " & Text1.Text & "#"

查不出记录。。为什么?
我用的 Set querydef1 = db.CreateQueryDef("", str)
Set rs = querydef1.OpenRecordset()
rs.movefirst
可是显示没有当前记录,在数据库中明明是有的



饮水需思源 2004-06-16
  • 打赏
  • 举报
回复
'数据库为ACCESS
strsql = "select * from test where " & Combo1.Text & " " & Combo2.Text & " # " & Text1.Text & "#"

'数据库为SQL
strsql = "select * from test where " & Combo1.Text & " " & Combo2.Text & " '" & Text1.Text & "'"

online 2004-06-16
  • 打赏
  • 举报
回复
'strsql = "select * from test where sj between # " & Text2.Text & " # and # " & Text3.Text & " #"
'strsql = "select * from test where sj between # " & DTPicker1.Value & " # and # " & DTPicker2.Value & " #"
strsql = "select * from test where sj >= # 2004-04-01 # and sj<= # 2004-06-24 #"

举了4种情况
strsql = "select * from test where " & Combo1.Text & " " & Combo2.Text & " # " & Text1.Text & "#"
banban1982 2004-06-16
  • 打赏
  • 举报
回复
str = " select * from bym where " + Combo1.Text + Combo2.Text + CDate(Text1.Text)

str = "select * from bym where " + Combo1.Text + Combo2.Text + "'" + Text1.Text + "'"

这2种写法也不对阿,另外说一下access中日期是这样的,如1995-6-3

1,216

社区成员

发帖
与我相关
我的任务
社区描述
VB 数据库(包含打印,安装,报表)
社区管理员
  • 数据库(包含打印,安装,报表)社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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