I would like to drop all the jobs related to a set of specific databases.
So I have added all the names into a table variable and I was trying to generate the scripts to drop the jobs.
how can I achieve this?
use msdb
go
DECLARE @R TABLE ( NAME VARCHAR(108) NOT NULL PRIMARY KEY CLUSTERED)
INSERT INTO @R(NAME)
SELECT
'UK15SUMMProduct' UNION ALL SELECT
'US15SUMMProduct' UNION ALL SELECT
'DE15SUMMProduct' UNION ALL SELECT
'AT15SUMMProduct' UNION ALL SELECT
'FR15SUMMProduct' UNION ALL SELECT
'EU15SUMMProduct' UNION ALL SELECT
'AU15SUMMProduct' UNION ALL SELECT
'UK15SUMSProduct' UNION ALL SELECT
'US15SUMSProduct' UNION ALL SELECT
'DE15SUMSProduct' UNION ALL SELECT
'AT15SUMSProduct' UNION ALL SELECT
'FR15SUMSProduct' UNION ALL SELECT
'EU15SUMSProduct' UNION ALL SELECT
'AU15SUMSProduct'
SELECT S.*
FROM SYSJOBS S
WHERE NAME LIKE ( SELECT NAME FROM @R)
something like the select above, I want to see all the jobs that have the database names in them and delete them, for example, like in the script below:
exec sp_delete_job @job_name = 'WebFeed UK15SUMMProduct', @delete_unused_schedule = 0
Best Answer
Here is the whole query:
Part of it is similar to previous answers.
You can replace values(...) by a table variable or a real table.