Invoking stored procedures on a target server

�Scheduled jobs often will invoke stored procedures on the target server to perform the required function. The following example shows a scheduled job invoking sp_who:�

use sybmgmtdb�
go
declare @jobcmd varchar(255), @jobid int�
select  @jobcmd=’jcmd=exec sp_who,server=YOUR_SERVER’�
+ ‘,starttime=’ + convert(varchar(32),getdate())�
exec @jobid=sp_sjobcreate ‘sjname=hello’, @jobcmd�
go

where YOUR_SERVER is the name of your target server.

NoteWhen Job Scheduler executes a job it prefixes the job text with SQL that creates the job runid and the scheduled job ID. Therefore, the call to sp_who needs to use exec to invoke the stored procedure.�