Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 creating a trigger to insert date on condition

Author  Topic 

sachingovekar
Posting Yak Master

101 Posts

Posted - 2010-07-24 : 12:59:13
Hi,

in A table I have a column of datetime
in B I have column in seconds (ie 7200seconds for 2 hrs )
In C I have a column again date time

create table #A(importdate datetime)
create table #B(SECONDS INT)
create table #C(importdate datetime)

When the application is inserting some values in C it shud check for A column time and Add B column seconds and if the Value in C is greator then A+B then it shud insert A+B. IF(A+B) > C then Insert C elseInsert (A+B)

For eg:
In A 24 July 2010 11:00 AM
In B 7200 sec
So A+ B = 24 July 2010 1:00PM
Now if i insert in C 24 July 2010 1:50 PM
den it shud insert A+B value

Regards,
sachin

slimt_slimt
Aged Yak Warrior

746 Posts

Posted - 2010-07-25 : 01:13:02
try this:


create table tA(id int identity(1,1),importdate datetime)
create table tB(id int identity(1,1),SECONDS INT)
create table tC(id int identity(1,1),importdate datetime)


create trigger DML_Trig_Tb_Tc
on tA
after insert, update
as
insert into tB
select 7200

declare @last_date_tA datetime
set @last_date_tA = ''

select top 1 @last_date_tA = importdate from tA order by id desc

insert into tC
select dateadd(s, 7200, @last_date_tA)
go


insert into tA select '2010/07/19'

select * from tA
select * from tB
select * from tC

drop table tA
drop table tB
drop table tC
Go to Top of Page
   

- Advertisement -