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 2005 Forums
 Transact-SQL (2005)
 job and email in sproc - imp

Author  Topic 

sqlhelp14
Yak Posting Veteran

55 Posts

Posted - 2008-01-21 : 10:59:01
In store procedure:

The sql job should run automatically each afternoon at 5pm

An email confirmation should be sent if data successfully completed.

i have idea like:

SET sMail = SERVER.CREATEOBJECT("ADODB.Connection")
sMail.Connectionstring = "Your Connection String"
sMail.Open
sMail.Execute("xp_startmail 'SEND ACCOUNT NAME'" )
sMail.Execute("xp_sendmail 'TO CLIENT ADDRESS',
@subject ='ANYTHING', @message ='SOMETHING' ,
@width=5000")
sMail.Execute("xp_stopmail")
sMail.Close

but how to use it in sproc and how to run sql job automaically in sproc using manually written code-logic.

do u have any idea about it??

Thanks.

RickD
Slow But Sure Yak Herding Master

3608 Posts

Posted - 2008-01-21 : 11:40:14
Create a scheduled job in SQL.
Go to Top of Page

rmiao
Master Smack Fu Yak Hacker

7266 Posts

Posted - 2008-01-21 : 15:23:04
Kind of confusion. Why start sql job in sp if you want to run the job at 5pm every day?
Go to Top of Page

khusiie
Yak Posting Veteran

78 Posts

Posted - 2008-01-21 : 15:27:48
i know how to schedule job thru sql agent but i need code - how to create it in store procedure..

if count<10 then
--start here to create job daily at 5pm...

so what should iwrite here??

select * from table where time =5pm

can u tell me?

thanks.
Go to Top of Page

rmiao
Master Smack Fu Yak Hacker

7266 Posts

Posted - 2008-01-21 : 15:31:16
With msdb..sp_add_job, but why create job in sp? Sql'll create job every time you run the sp.
Go to Top of Page
   

- Advertisement -