Query to check if job already belongs to jobserver in MSSQL I am working with a legacy migration script that was setup to add a job (With a number of steps) to a MSSQL server. I am trying to build in some semblance of re-runable without it completely blowing up.

However I am now down to this line :

EXEC @ReturnCode = msdb.dbo.sp_add_jobserver @job_id = @jobId, @server_name = N'(local)'


If the job already belongs to the local server, then this line will error. It's very feasible that this might be run several times.

Is there a query that I could run to check whether a job already belongs to local (Or any other servername?)
Found my solution. 

IF NOT EXISTS(SELECT * FROM msdb.dbo.sysjobservers WHERE (job_id = @myJobId AND server_id = 0))