| | |
how to send emails using triggers
Please support our MS SQL advertiser: Intel Parallel Studio Home
![]() |
hi,
i want to elaborate wat exactly i want.trigger executes only after update or insert or delete occurs.i want to know how to delete rows even if the administrator didnt update or insert or didnt touch the datebase for few days,then aslo we should be able to delete rows and mails should be sent notifying the administrator about deleting rows.
i want to elaborate wat exactly i want.trigger executes only after update or insert or delete occurs.i want to know how to delete rows even if the administrator didnt update or insert or didnt touch the datebase for few days,then aslo we should be able to delete rows and mails should be sent notifying the administrator about deleting rows.
my code is like this
CREATE TRIGGER [trg_job] ON [dbo].[JobPost]
FOR INSERT, UPDATE, DELETE
AS
set nocount on
declare @msg varchar(2000),
@postingdate nvarchar(50),
@applydays nvarchar(30),
@jobexpirydate nvarchar(30)
declare email_cur CURSOR
for
select postingdate,applydays,jobexpirydate from jobpost
where jobexpirydate = dateadd(dd, 2,getdate())
open email_cur
fetch next from email_cur into @postingdate, @applydays, @jobexpirydate
while @@Fetch_status=0
begin
set @msg='Dear row will be deleted'
exec master.dbo.xp_sendmail @recipients='xxx@yyy.com', @message=@msg,
@subject='delete Notification'
fetch next from email_cur into @postingdate, @applydays, @jobexpirydate
end
deallocate email_cur
CREATE TRIGGER [trg_job] ON [dbo].[JobPost]
FOR INSERT, UPDATE, DELETE
AS
set nocount on
declare @msg varchar(2000),
@postingdate nvarchar(50),
@applydays nvarchar(30),
@jobexpirydate nvarchar(30)
declare email_cur CURSOR
for
select postingdate,applydays,jobexpirydate from jobpost
where jobexpirydate = dateadd(dd, 2,getdate())
open email_cur
fetch next from email_cur into @postingdate, @applydays, @jobexpirydate
while @@Fetch_status=0
begin
set @msg='Dear row will be deleted'
exec master.dbo.xp_sendmail @recipients='xxx@yyy.com', @message=@msg,
@subject='delete Notification'
fetch next from email_cur into @postingdate, @applydays, @jobexpirydate
end
deallocate email_cur
![]() |
Similar Threads
- Hotmail wont let me send emails (Web Browsers)
- Cannot send any mail from hotmail (Web Browsers)
- Can't send emails using my neighbour's Netgear network (Networking Hardware Configuration)
- Error message 550 when sending emails (Web Browsers)
- sending emails on hotmail (Web Browsers)
Other Threads in the MS SQL Forum
- Previous Thread: Stored procedure with Dynamic columns?
- Next Thread: Need some help with T-SQL where logic syntax
| Thread Tools | Search this Thread |
autogrowth connectingtodatabaseinuse count cursor data database datepart dbsize deadlock delete_trigger highperformancecomputing hpc hpcserver2008 ibm iis loop maximum microsoft ms mssql multithreading news number permission query reporting result server services sets source sql sqlserver sqlserver2005 supercomputing uniqueid update view






