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
 General SQL Server Forums
 New to SQL Server Programming
 Trgger After Insert

Author  Topic 

sent_sara
Constraint Violating Yak Guru

377 Posts

Posted - 2008-07-21 : 01:22:06
Can any one correct my query,If iam wrong.
I need to delete those record which is less than 10 days from the current date.After the insertion happens in status_report table.

Create trigger trg_status_report on status_report
for insert
--After in--(??)
as
begin
delete from fin_wh.dbo.status_report
where datediff(dd,getdate()-4,st_date)<2
end

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2008-07-21 : 01:26:07
"I need to delete those record which is less than 10 days from the current date"

less than 10 days ?

delete d
from status_report d
where d.st_date >= dateadd(day, datediff(day, 0, getdate()), -10)



KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

sent_sara
Constraint Violating Yak Guru

377 Posts

Posted - 2008-07-21 : 01:33:12
I need to delete after the insertion happens to the table[status_report].whether after insert keyword need to be incorporate in trigger???

quote:
Originally posted by khtan

"I need to delete those record which is less than 10 days from the current date"

less than 10 days ?

delete d
from status_report d
where d.st_date >= dateadd(day, datediff(day, 0, getdate()), -10)



KH
[spoiler]Time is always against us[/spoiler]



Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2008-07-21 : 01:40:18
[code]CREATE trigger trg_status_report
ON status_report
FOR INSERT
AS
BEGIN
DELETE d
FROM status_report d
WHERE d.st_date >= DATEADD(DAY, DATEDIFF(DAY, 0, GETDATE()), -10)
END[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

sent_sara
Constraint Violating Yak Guru

377 Posts

Posted - 2008-07-21 : 01:50:24
txs khtan

quote:
Originally posted by khtan

CREATE trigger trg_status_report 
ON status_report
FOR INSERT
AS
BEGIN
DELETE d
FROM status_report d
WHERE d.st_date >= DATEADD(DAY, DATEDIFF(DAY, 0, GETDATE()), -10)
END



KH
[spoiler]Time is always against us[/spoiler]



Go to Top of Page
   

- Advertisement -