DELETE scripts WHERE name = 'script_tasks' GO INSERT scripts VALUES('script_tasks','SET NOCOUNT ON') INSERT scripts VALUES('script_tasks','PRINT "/*"') INSERT scripts VALUES('script_tasks','PRINT " NOTES: Use single quotes only when setting up tasks."') INSERT scripts VALUES('script_tasks','PRINT " This utility will wrap all character data in"') INSERT scripts VALUES('script_tasks','PRINT " double quotes. If you automate a restore from"') INSERT scripts VALUES('script_tasks','PRINT " this script, be sure to drop existing tasks to"') INSERT scripts VALUES('script_tasks','PRINT " prevent duplicates."') INSERT scripts VALUES('script_tasks','PRINT " "') INSERT scripts VALUES('script_tasks','PRINT " sp_addtask name,"') INSERT scripts VALUES('script_tasks','PRINT " subsystem, server, username, databasename, "') INSERT scripts VALUES('script_tasks','PRINT " enabled, -- 0=disabled, 1=enable,"') INSERT scripts VALUES('script_tasks','PRINT " freqtype, freqinterval,"') INSERT scripts VALUES('script_tasks','PRINT " freqsubtype, freqsubinterval,"') INSERT scripts VALUES('script_tasks','PRINT " freqrelativeinterval, freqrecurrencefactor,"') INSERT scripts VALUES('script_tasks','PRINT " activestartdate, activeenddate,"') INSERT scripts VALUES('script_tasks','PRINT " activestarttimeofday, activeendtimeofday,"') INSERT scripts VALUES('script_tasks','PRINT " nextrundate, nextruntime, runpriority,"') INSERT scripts VALUES('script_tasks','PRINT " emailoperatorname, retryattempts, retrydelay,"') INSERT scripts VALUES('script_tasks','PRINT " command,"') INSERT scripts VALUES('script_tasks','PRINT " loghistcompletionlevel, emailcompletionlevel,"') INSERT scripts VALUES('script_tasks','PRINT " description"') INSERT scripts VALUES('script_tasks','PRINT "*/"') INSERT scripts VALUES('script_tasks','') INSERT scripts VALUES('script_tasks','SELECT "msdb..sp_addtask ",') INSERT scripts VALUES('script_tasks',' (CHAR(34) + RTRIM(name) + CHAR(34) + CHAR(44)),') INSERT scripts VALUES('script_tasks',' CHAR(13)," ",') INSERT scripts VALUES('script_tasks',' (CHAR(34) + RTRIM(subsystem) + CHAR(34) +') INSERT scripts VALUES('script_tasks',' ",@@SERVERNAME," +') INSERT scripts VALUES('script_tasks',' CHAR(34) +') INSERT scripts VALUES('script_tasks',' RTRIM((SELECT name FROM master..syslogins') INSERT scripts VALUES('script_tasks',' WHERE suid = ownerloginid)) +') INSERT scripts VALUES('script_tasks',' CHAR(34) + CHAR(44) + CHAR(34) +') INSERT scripts VALUES('script_tasks',' RTRIM(databasename) + CHAR(34) + CHAR(44)),') INSERT scripts VALUES('script_tasks',' CHAR(13)," ",') INSERT scripts VALUES('script_tasks',' (RTRIM(CONVERT(CHAR(1),enabled)) + CHAR(44)),') INSERT scripts VALUES('script_tasks',' CHAR(13)," ",') INSERT scripts VALUES('script_tasks',' (RTRIM(CONVERT(CHAR(3),freqtype)) + CHAR(44) +') INSERT scripts VALUES('script_tasks',' RTRIM(CONVERT(CHAR(3),freqinterval)) + CHAR(44)),') INSERT scripts VALUES('script_tasks',' CHAR(13)," ",') INSERT scripts VALUES('script_tasks',' (RTRIM(CONVERT(CHAR(3),freqsubtype)) + CHAR(44) +') INSERT scripts VALUES('script_tasks',' RTRIM(CONVERT(CHAR(3),freqsubinterval)) + CHAR(44)),') INSERT scripts VALUES('script_tasks',' CHAR(13)," ",') INSERT scripts VALUES('script_tasks',' (RTRIM(CONVERT(CHAR(3),freqrelativeinterval)) + CHAR(44) +') INSERT scripts VALUES('script_tasks',' RTRIM(CONVERT(CHAR(3),freqrecurrencefactor)) + CHAR(44)),') INSERT scripts VALUES('script_tasks',' CHAR(13)," ",') INSERT scripts VALUES('script_tasks',' (RTRIM(CONVERT(CHAR(8),activestartdate)) + CHAR(44) +') INSERT scripts VALUES('script_tasks',' RTRIM(CONVERT(CHAR(8),activeenddate)) + CHAR(44)),') INSERT scripts VALUES('script_tasks',' CHAR(13)," ",') INSERT scripts VALUES('script_tasks',' (RTRIM(CONVERT(CHAR(6),activestarttimeofday)) + CHAR(44) +') INSERT scripts VALUES('script_tasks',' RTRIM(CONVERT(CHAR(6),activeendtimeofday)) + CHAR(44)),') INSERT scripts VALUES('script_tasks',' CHAR(13)," ",') INSERT scripts VALUES('script_tasks',' (RTRIM(CONVERT(CHAR(8),nextrundate)) + CHAR(44) +') INSERT scripts VALUES('script_tasks',' RTRIM(CONVERT(CHAR(6),nextruntime)) + CHAR(44) +') INSERT scripts VALUES('script_tasks',' RTRIM(CONVERT(CHAR(2),runpriority)) + CHAR(44)),') INSERT scripts VALUES('script_tasks',' CHAR(13)," ",') INSERT scripts VALUES('script_tasks',' (CHAR(34) +') INSERT scripts VALUES('script_tasks',' RTRIM((SELECT name FROM msdb..sysoperators') INSERT scripts VALUES('script_tasks',' WHERE id = emailoperatorid)) +') INSERT scripts VALUES('script_tasks',' CHAR(34) + CHAR(44) +') INSERT scripts VALUES('script_tasks',' CONVERT(CHAR(1),retryattempts) + CHAR(44) +') INSERT scripts VALUES('script_tasks',' CONVERT(CHAR(1),retrydelay) + CHAR(44)),') INSERT scripts VALUES('script_tasks',' CHAR(13)," ",') INSERT scripts VALUES('script_tasks',' (CHAR(34) + RTRIM(command) + CHAR(34) + CHAR(44)),') INSERT scripts VALUES('script_tasks',' CHAR(13)," ",') INSERT scripts VALUES('script_tasks',' (CONVERT(CHAR(1),loghistcompletionlevel) + CHAR(44) +') INSERT scripts VALUES('script_tasks',' CONVERT(CHAR(1),emailcompletionlevel) + CHAR(44)),') INSERT scripts VALUES('script_tasks',' CHAR(13)," ",') INSERT scripts VALUES('script_tasks',' (CHAR(34) + RTRIM(description) + CHAR(34)),') INSERT scripts VALUES('script_tasks',' CHAR(13),"GO",CHAR(13)') INSERT scripts VALUES('script_tasks','FROM msdb..systasks')