这两条SQL语句应该怎么写,比较好?

casear_huang 2002-02-27 12:46:57
我有一个表cd_task(任务表),其中有两个字段plan_start(计划开始时间),plan_end(计划结束时间)
我现在要找出本月的任务,和本周的任务。
这两条SQL语句应该怎么写,比较好?
...全文
46 16 打赏 收藏 转发到动态 举报
写回复
用AI写文章
16 条回复
切换为时间正序
请发表友善的回复…
发表回复
casear_huang 2002-02-27
  • 打赏
  • 举报
回复
To:ChinaOk(蓝蝶)
没错,不过,比较麻烦,我想知道有没有简单一点的方法。
playmud 2002-02-27
  • 打赏
  • 举报
回复
不是日期类型的转换成日期类型的呗
playmud 2002-02-27
  • 打赏
  • 举报
回复
首先取当前时间data1,月,还有日,星期,然后通过判断得到本月的起始日期date2,本星期的起始日期date3,然后
本月任务
select * from table where plan_start>data2 and plan_end<data1
本周计划
select * from table where plan_start>data3 and plan_end<data1
casear_huang 2002-02-27
  • 打赏
  • 举报
回复
这样不行,说明一下,两个字段保存的都是YY/MM/DD这种格式,
你这样的sql语句得到是今天的。
ChinaOk 2002-02-27
  • 打赏
  • 举报
回复
从现在的时间里计算出出本周的开始时间。和本月的开始时间然后再生成查询sql不就可以了。
playmud 2002-02-27
  • 打赏
  • 举报
回复
首先取当前时间data1,月,还有日,星期,然后通过判断得到本月的起始日期date2,本星期的起始日期date3,然后
本月任务
select * from table where date<data1 and date>data2
本周计划
select * from table where date<data1 and date>data3
casear_huang 2002-02-27
  • 打赏
  • 举报
回复
问题已经解决,这两句应该这么写!

"(DateDiff(""m"",plan_start,'"&Date()&"') >= 0 And DateDiff(""m"",plan_end,'"&Date()&"') <= 0)"

SQL = "(DateDiff(""ww"",plan_start,'"&Date()&"') >= 0 And DateDiff(""ww"",plan_end,'"&Date()&"') <= 0)"
playmud 2002-02-27
  • 打赏
  • 举报
回复
SELECT *
FROM table
WHERE (date > '1999/9/9')
这样的可以执行呀
playmud 2002-02-27
  • 打赏
  • 举报
回复
少了"
playmud 2002-02-27
  • 打赏
  • 举报
回复
sql="select * from table where plan_start>'"&date_year&"/"&date_month&"/"&date_day&" and
plan_end<'"&date_year&"/"&date_month&"/"&date_day&" order by task_id
desc
casear_huang 2002-02-27
  • 打赏
  • 举报
回复
那你怎么写?
playmud 2002-02-27
  • 打赏
  • 举报
回复
不用分开来比较!!!
playmud 2002-02-27
  • 打赏
  • 举报
回复
别用between
casear_huang 2002-02-27
  • 打赏
  • 举报
回复
上面那个帖子date_year=Year(date()),date_month=Month(date())
希偌 2002-02-27
  • 打赏
  • 举报
回复
用between
casear_huang 2002-02-27
  • 打赏
  • 举报
回复
这是我写的,我就是觉得比较麻烦,想找简单的方法
SQL = "(('"&date_year&"' > Year(plan_start) And '"&date_year&"' < Year(plan_end)) Or ('"&date_year&"' > Year(plan_start) And ('"&date_year&"' = Year(plan_end) And '"&date_month&"'<= Month(plan_end))) Or (('"&date_year&"' = Year(plan_start) And '"&date_month&"' >= Month(plan_start)) And '"&date_year&"' < Year(plan_end)) Or (('"&date_year&"' = Year(plan_start) And '"&date_month&"' >= Month(plan_start)) And ('"&date_year&"' = Year(plan_end) And '"&date_month&"' <= Month(plan_end)))) "
SQL = "Select * "&SQL& " Order By task_id Desc"

28,406

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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