延后12小时插入不好處理?可使用job,但要另寫代碼處理。CREATE TRIGGER tr_insert
ON a
FOR INSERT
AS
   insert into B(...)
   select ...
   from inserted A
   inner join c on c.Id=A.Id
   where getdate()>=C.S1 and getdate()<=C.S2go

解决方案 »

  1.   

    不是延后再插入,而是把时间都改为在原时间上日加一天,然后小时为c.S1,还有好像不可以直接用getdate()>=C.S1 and getdate()<=C.S2,因为C.S1和 C.S2是字符型的,而需要的是数值型的比,还只是比较小时,因为要去时间范围,你看有什么办法吗
      

  2.   

    create trigger trig_a on a
    for insert
    as
    begin
        
        if exits((select into_date from inserted) between (select s1 from c) and (select s2 from c) then
              update a set into_date=dateadd(hh,12,into_date) 
                          where Id=inserted.Id
        insert into b 
                  select * from a inner join inserted on a.Id=inserted.Id
    end
      

  3.   

    CREATE TRIGGER tr_insert
    ON a
    FOR INSERT
    AS
       --符合條件的進行插入
       insert into B(...)
       select ...
       from inserted A
       inner join c on c.Id=A.Id
       where datediff(hh,C.S1 ,getdate())>=0 and datediff(hh,C.S2 ,getdate())<=0   --不符合條件的進行時間更改
       update A
       set A.into_date =dateadd(hh,12,A.into_date ) --加12小時
       from inserted B
       inner join A on A.Id=B.Id
       inner join c on c.Id=A.Id
       where not(datediff(hh,C.S1 ,getdate())>=0 and datediff(hh,C.S2 ,getdate())<=0)go
      

  4.   

    --a,c表通过name关联,而且只比较小时部分
    create trigger tr_insert on a
    after insert
    as
    --更新不匹配的时间
    update a set into_date=dateadd(hour,12,a.into_date)
    from a 
    join inserted b on a.id=b.id
    join c on b.name=c.name
    where convert(varchar(2),b.into_date,108) 
    between c.s1 and c.s2
    insert b(mssage,into_date)
    select a.mssage,a.into_date
    from a join inserted b on a.id=b.id
    go
      

  5.   

    是的,c表通过name,不过, koskinen(努力,奋斗!) ,您得好像不通呀,包错
      

  6.   

    不不,错了,对不起,a,c表是通过a.nameid=c.id 连接的,不好意思
      

  7.   

    --你的a表中没有nameid这个字段啊create trigger tr_insert on a
    after insert
    as
    --更新不匹配的时间
    update a set into_date=dateadd(hour,12,a.into_date)
    from a 
    join inserted b on a.id=b.id
    join c on .nameid=c.id
    where convert(varchar(2),b.into_date,108) 
    between c.s1 and c.s2
    insert b(mssage,into_date)
    select a.mssage,a.into_date
    from a join inserted b on a.id=b.id