有一个表(T1)中有日期和时间为同一列:2009-9-14 19:55:59
现要做一个触发器向(T1)插入数据时更新数据到(T2),但是要跳过 如果日期(2009-9-4)为星期一和时间(19:55:59)大于20点,小于16点的数据。
能不能实现这样的功能?请手解答,谢谢
现要做一个触发器向(T1)插入数据时更新数据到(T2),但是要跳过 如果日期(2009-9-4)为星期一和时间(19:55:59)大于20点,小于16点的数据。
能不能实现这样的功能?请手解答,谢谢
解决方案 »
- sql创建一个存储过程或者触发器实现对纪录的编号,要求编号不同,当纪录删除时编号不会重复
- 一个关于同步两个表的数据的问题
- 求同一个表的UPDATE语句..
- SQL SERVER2008数据库邮件错误:请求的名称有效但是找不到请求类型的数据
- 用代码怎样打开Database的代码
- 这个是补给 libin_ftsafe(子陌红尘) 的 400 分的帖子(2/4)
- 遇到sql2005怪问题,过程'syusabgd' 的请求失败,因为 'syusabgd' 是 表 对象。
- 代码改成存储过程
- sqlserver里是否有自动增加字段类型,如何苗速,又如何对该纪录进行insert?
- 出库表的触发器怎么写?
- 求一条统计sql语句
- 数据库User表预计有5000万用户,这个表要拆分吗?
and
alter table t1 enable trigger [trigger_name]
at the end of your maintenance taskIf the latter, you simply need something like the following in the trigger itself:
create trigger mytrigger on t1 for insert as
set nocount on
set datefirst 1 --set monday to be 1
insert into t2
select
a.*
from
inserted a inner join t2 b on
a.joiningkey=b.joiningkey
where
not (datepart(weekday, a.datetimefield)=1 and
datepart(hour, a.datetimefield) between 16 and 20)
go
on T1
for insert
as
begin
update T2 set .....from inserted
where datename(weekday,时间列)<>'星期一' and datepart(hour,时间列) not between 16 and 20
end
on T1
for insert
as
begin
insert T2 select * from inserted
where datename(weekday,time)<>'星期一' and datepart(hour,time) not between 16 and 20
end可以跳过星期一,但是时上的限制不生效,现在想把星期六的一起过滤掉,能不能怎么修改一下来实现?
谢谢