SQL语句以日期为条件查询怎么写?

johnnysun 2002-06-09 04:20:13
select * from table where inputdate___________?
我想以输入日期inputdate为条件查询本月、季度、年度内的记录,这句应该怎么写?我想好久了,仍没有好的办法。大侠们帮我啊。
...全文
2606 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
watt 2002-06-09
  • 打赏
  • 举报
回复
用Datediff函数最后,此函数可得日,月,年等的差,差为0即为同日,月,年,剩下的问题你自己可能处理了吧!因为时间还有时分秒,毫秒等。
wzsswz 2002-06-09
  • 打赏
  • 举报
回复
要判断某月最后一天,编个procedure即可。
wzsswz 2002-06-09
  • 打赏
  • 举报
回复
dim medate as string
medate = rtrim(t_date.text)
本月:
sql = "select * from table where month(inputdate) = month('"+medate+"')"
本年度:
sql = "select * from table where year(inputdate) = year('"+medate+"')"
本季度:
dim stdt as string
dim eddt as string

sql = "select * from table where inputdate = '"+stdt+"' and '"+eddt+"'"

johnnysun 2002-06-09
  • 打赏
  • 举报
回复
当我使用select * from table where inputdate=#2002-6-31#
就出错了,我还要判断六月有没有31号,有什么简单的方法吗?
tj_aj 2002-06-09
  • 打赏
  • 举报
回复
access:where timeField>#2002-1-1#
sqlServer or Oracle 等等可以把时间字段作为字符处理
或可以用各个数据库中特有的函数
如access中 cdate('')
oracel中 to_date('','yyyy-mm-dd')
hengxin54 2002-06-09
  • 打赏
  • 举报
回复
select * from table where inputdate=#日期# , 这样应该可以吧
select * from table where inputdate between #日期1# and #日期2#
jmlmj 2002-06-09
  • 打赏
  • 举报
回复
#yyyy-M-d#

7,764

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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