主要代码如下: declare @tta datetime select @tta=max([时间]) from A表 if datediff(hour,@tta,getdate())>3 insert into B表(....)values(....)---把上述代码放到一个作业里,可定义1分钟执行一次
如是按你说的上述代码改动如下:declare @tta datetime declare @usr varchar(12) declare cur cursor for select user1,time1 from A表 open cur fetch next from cur into @usr,@tta while @@fetch_status=0 begin if datediff(hour,@tta,getdate())>3 insert into B表 select @usr,@usr fetch next from cur into @usr,@tta end close cur deallocate cur
谢谢楼上,基本上我弄得差不多了 不过能否解释一下datediff这个函数具体怎么用的实际上在A表里,我是放了year,month,day三个字段,然后系统时间距离(year+month+day)3天的时候,执行插入操作 改成 if datediff(day,@year+@month+@day,getdate())>3 对吗?为什么是>3而不是等于然后在作业里我是设定为每天下午3点钟运行存储过程,这样可以的吧
2用户给一个时间,比如2005年9月18日存在A表中,那么9月18日下午3点中,系统就会执行插入B表的操作
请大家帮忙啊
系统扫描A表中所有用户的时间,如果符合当前时间,那么就执行插入B表的操作,如是1用户,插入(1,1),是2用户,插入(2,2)
declare @tta datetime
select @tta=max([时间]) from A表
if datediff(hour,@tta,getdate())>3
insert into B表(....)values(....)---把上述代码放到一个作业里,可定义1分钟执行一次
declare @usr varchar(12)
declare cur cursor for
select user1,time1 from A表
open cur
fetch next from cur into @usr,@tta
while @@fetch_status=0
begin
if datediff(hour,@tta,getdate())>3
insert into B表 select @usr,@usr
fetch next from cur into @usr,@tta
end
close cur
deallocate cur
不过能否解释一下datediff这个函数具体怎么用的实际上在A表里,我是放了year,month,day三个字段,然后系统时间距离(year+month+day)3天的时候,执行插入操作
改成 if datediff(day,@year+@month+@day,getdate())>3 对吗?为什么是>3而不是等于然后在作业里我是设定为每天下午3点钟运行存储过程,这样可以的吧