高分求购SQL语句(ASP+access)!

chrx229 2007-01-17 10:11:23
table 中有字段count(整数),time(日期/时间),days(整数)
要求:
如果当前时间减去time中的时间 > days中的天数,
则更新这条记录的count为count+1,请写出完整的update语句。
...全文
384 21 打赏 收藏 转发到动态 举报
写回复
用AI写文章
21 条回复
切换为时间正序
请发表友善的回复…
发表回复
feifeizaizhe 2007-01-20
  • 打赏
  • 举报
回复
过程。
Mapleleaf123 2007-01-20
  • 打赏
  • 举报
回复
sql="update [songhua] set ToName='"&Toname&"',posttime='"&now()&"' where posttime=(select top 1 posttime from [songhua] where datediff('d',posttime,now()) > days)"

conn.execute(sql)

都试晕了!
就是不行,帮我检查一下吧
//
response.write SQL
看看
fusoft 2007-01-19
  • 打赏
  • 举报
回复
SQL的保留字都有哪些?

ACCESS 和 MS SQL Server 的不一样!
李睿_Lee 2007-01-19
  • 打赏
  • 举报
回复
晕,不会自己加个Where 啊???
要学会举一反三。。
不然你问了一次,下次碰到类似的还得问。
chrx229 2007-01-19
  • 打赏
  • 举报
回复
sql="update [songhua] set ToName='"&Toname&"',posttime='"&now()&"' where posttime=(select top 1 posttime from [songhua] where datediff('d',posttime,now()) > days)"

conn.execute(sql)

都试晕了!
就是不行,帮我检查一下吧!
jxf654 2007-01-18
  • 打赏
  • 举报
回复
up
  • 打赏
  • 举报
回复
update 表名 set [count]=[count]+1 where DateDiff("d",[time],now()) > days

  • 打赏
  • 举报
回复
update 表名 set count=count+1 where DateDiff("d",time,now()) > days
zysoft17 2007-01-18
  • 打赏
  • 举报
回复
试试这句:

update 表名 set count=count+1 where DateDiff("d",time,Date()) > days
chrx229 2007-01-18
  • 打赏
  • 举报
回复
试了,正如预料的那样:
结果把符合条件的记录全更新了!

我的要求是只更新符合条件的time值最早的一条就好,其他记录不更新。

还望高手们鼎力相帮啊!
问题解决了,一定给分!
ishion 2007-01-18
  • 打赏
  • 举报
回复
update 表名 set count=count+1 where DateDiff("d",time,now()) > days
cow8063 2007-01-18
  • 打赏
  • 举报
回复
都说对了,我就不说了
uglyman8246 2007-01-18
  • 打赏
  • 举报
回复
update 表名 set [count]=[count]+1 where DateDiff("s",[time],now()) > (days * 86400)
就这样写就可以了
chrx229 2007-01-18
  • 打赏
  • 举报
回复
试一下,就怕不是只更新最早时间的一条记录,而把符合条件的所有记录全更新了!
lhfx1985 2007-01-18
  • 打赏
  • 举报
回复
update 表名 set [count]=[count]+1 where DateDiff("d",[time],now()) > days
应该就可以了!~
chuckcoin 2007-01-18
  • 打赏
  • 举报
回复
晕~自己换算一下都不行呀~
update 表名 set [count]=[count]+1 where DateDiff("s",[time],now()) > (days * 86400)
chrx229 2007-01-18
  • 打赏
  • 举报
回复
对了,在SQL语句中count会不会是保留字,即表中用count作字段名会不会
导致SQL执行出错?

SQL的保留字都有哪些?
chrx229 2007-01-18
  • 打赏
  • 举报
回复
这样是不是会把符合条件的记录全都更新了?

我没说明白:
1、只要求更新符合条件的时间最早的那一条记录

2、时间差至少精确到分,最好能精确到秒

即1天要相隔完整的24小时才算
举例:
1/18 23:59:59到1/19 23:59:59后才算1天,
否则1/18 23:59:59到1/19 00:00:01已相差1天,
但只隔2秒,这样就不符合要求!

fest 2007-01-18
  • 打赏
  • 举报
回复
楼上的几位写法可行,不过效率高点可以这样写

declare @ValidTime datetime
set @ValidTime=dateadd(day,-days, getdate())
update 表名 set count=count+1 where [time]<@ValidTime
hurrayboy 2007-01-17
  • 打赏
  • 举报
回复
个人感觉在ASP中是还各简单一些.
Access功能太弱了.

UP...
加载更多回复(1)

28,391

社区成员

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

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