日期:2014-05-19  浏览次数:20373 次

子陌哥哥帮忙呀~~~~~~~~~~~~~~~~~~~~~
现在a表内容如下

kaiyongshijian                       shedingshijian     ID         beizhu
2007-4-3   12:00:00                   12                         1        
2007-4-3   12:00:00                   15                         5
2007-4-3     12:00:00                 20                         9
表B
zhengdianbaoshi                       ID         beizhu
2007-4-3   12:12:00                   1        
2007-4-3   12:15:00                   5
2007-4-3   12:20:00                   9
2007-4-3   12:24:00                   1
2007-4-3   12:30:00                   5
2007-4-3   12:36:00                   1
请教下该触发器怎么写?或者每天运行一次把所有的列出的句子
shedingshijian列就是需要时间12分钟,15分钟,20分钟,应该还有另外简单的方法吧?

------解决方案--------------------
每天运行一次??

建立一个作业?
------解决方案--------------------
create trigger test_tr on dbo.a
for insert
as
insert b
select kaiyongshijian+( '00: '+rtrim(shedingshijian),ID from inserted
------解决方案--------------------
create table a
(
kaiyongshijian datetime,
shedingshijian int,
ID int,
beizhu varchar(5)
)

insert into a
select '2007-4-3 12:00:00 ',12,1 null union all
select '2007-4-3 12:00:00 ',15,5 null union all
select '2007-4-3 12:00:00 ',20,9
go
create trigger tritest
on a
for insert
as
declare @i int
set @i=0
while dateadd(minute,inserted.shedingshijian*@i,inserted.kaiyongshijian) <= cast(convert(char(10),dateadd(day,1,inserted.kaiyongshijian),120) as datetime)
begin
insert into b select dateadd(minute,inserted.shedingshijian*@i,inserted.kaiyongshijian),inserted.id,null
set @i=@i+1
end
------解决方案--------------------
帮你顶一下。。关注