﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>SQLServerCentral / SQL Server 2008 / SQL Server 2008 High Availability  / SQL JOBS Not Functioning / Latest Posts</title><generator>InstantForum.NET v2.9.0</generator><description>SQLServerCentral</description><link>http://www.sqlservercentral.com/Forums/</link><webMaster>notifications@sqlservercentral.com</webMaster><lastBuildDate>Mon, 20 May 2013 09:16:55 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: SQL JOBS Not Functioning</title><link>http://www.sqlservercentral.com/Forums/Topic1386299-1549-1.aspx</link><description>You can use below script by just enter the database name which you want to exclude and provide the spname as input variable.DECLARE @SPNAME VARCHAR(100)DECLARE @DBNAME VARCHAR(100)DECLARE @SQLCMD VARCHAR(1000)SET @SPNAME = 'MY_SP'DECLARE CUR1 CURSOR FORSELECT NAME FROM SYSDATABASES WHERE NAME NOT IN ('MASTER','MODEL','MSDB','TEMPDB')OPEN CUR1FETCH NEXT FROM CUR1 INTO @DBNAMEWHILE @@FETCH_STATUS=0BEGINSET @SQLCMD = 'EXEC '+@DBNAME+'.DBO.'+@SPNAME+''--PRINT(@SQLCMD)EXEC(@SQLCMD)FETCH NEXT FROM CUR1 INTO @DBNAMEENDCLOSE CUR1DEALLOCATE CUR1GO</description><pubDate>Tue, 27 Nov 2012 23:23:55 GMT</pubDate><dc:creator>kvishu83</dc:creator></item><item><title>RE: SQL JOBS Not Functioning</title><link>http://www.sqlservercentral.com/Forums/Topic1386299-1549-1.aspx</link><description>Hi Anthony,I have modified the Script, i need one more help in the scriptWhat i have done is if the Script fails for any DB it will entry the record in One table.. so that i will come to know which DB was failed to execute the Script.*************************************DECLARE @SQL NVARCHAR(MAX)SELECT @SQL = 	REPLACE(		CAST(			(				SELECT 'USE ' + QUOTENAME(name) +';' + CHAR(13) + CHAR(10) +				'Begin Try 							 EXECUTE dbo.Test_SP;				 End Try				 Begin Catch					Use Master					Insert into Runal_Job (DBName,FailureType) values('''+name+''',''Log'')				 End Catch				 '+CHAR(13)+CHAR(10)				FROM sys.databases WHERE name IN ('DB1','DB2')				FOR XML PATH('')			) AS NVARCHAR(MAX)		),		'&amp;#x0D;',CHAR(13) + CHAR(10)	)--SELECT @SQL--print @SQLEXECUTE sp_executesql @SQL--Use Master--select * from Runal_Job*************************************I want to add the time constraint in this..as some time it takes hours to execute the script for one DB &amp; due to which it may affect the performance..Can you please help me with the Time query..ao that if the script runs for more than half hour it should automatically kill the execution for that DB..Secondly one more question If there are 3 DB's &amp; this script will run for first &amp; then for second &amp; then for third..What if it fails for 2nd DB, will it leave the 2nd DB &amp; run 1 &amp; 3?????</description><pubDate>Wed, 21 Nov 2012 05:04:35 GMT</pubDate><dc:creator>OnlyOneRJ</dc:creator></item><item><title>RE: SQL JOBS Not Functioning</title><link>http://www.sqlservercentral.com/Forums/Topic1386299-1549-1.aspx</link><description>Thanks Sure :-)</description><pubDate>Wed, 21 Nov 2012 04:13:33 GMT</pubDate><dc:creator>OnlyOneRJ</dc:creator></item><item><title>RE: SQL JOBS Not Functioning</title><link>http://www.sqlservercentral.com/Forums/Topic1386299-1549-1.aspx</link><description>Any it does not matter as it will execute the procedure in every database you have in sys.databases unless you specifically exlcude it in the exclusions list.Uncomment the SELECT @SQL line, comment out the EXEC sp_executesql line and run it, you will see what the command is doing.It basically generatesUSE [database1];EXECUTE dbo.thisismyprocedure;USE [datebase2];EXECUTE dbo.thisismyprocedure;etcetcetc</description><pubDate>Tue, 20 Nov 2012 04:59:38 GMT</pubDate><dc:creator>anthony.green</dc:creator></item><item><title>RE: SQL JOBS Not Functioning</title><link>http://www.sqlservercentral.com/Forums/Topic1386299-1549-1.aspx</link><description>I got it, but one question while copying this is command pane.. there we have to select the database also?? by defauklt it is Master, what should i choose???</description><pubDate>Tue, 20 Nov 2012 04:56:50 GMT</pubDate><dc:creator>OnlyOneRJ</dc:creator></item><item><title>RE: SQL JOBS Not Functioning</title><link>http://www.sqlservercentral.com/Forums/Topic1386299-1549-1.aspx</link><description>Use my code, the only thing you need to do is to replace the the text [b]schema.procedure[/b] with the name of your procedure eg. [b]dbo.thisismyprocedure[/b]Then remove the spaces between the '&amp; # x 0 D ;'The last step should be exec sp_executesql @sql do not change that line.</description><pubDate>Tue, 20 Nov 2012 04:53:24 GMT</pubDate><dc:creator>anthony.green</dc:creator></item><item><title>RE: SQL JOBS Not Functioning</title><link>http://www.sqlservercentral.com/Forums/Topic1386299-1549-1.aspx</link><description>thanks Shell.. will try to implement itAnthony - Do u want me to paste the entire code in Command pane ending with Exec SP???example - DECLARE @SQL NVARCHAR(MAX)SELECT @SQL = 	REPLACE(		CAST(			(				SELECT 'USE ' + QUOTENAME(name) +';' + CHAR(13) + CHAR(10) +				'EXECUTE schema.procedure;'+CHAR(13)+CHAR(10)				FROM sys.databases WHERE name NOT IN ('master','msdb','model','tempdb')				FOR XML PATH('')			) AS NVARCHAR(MAX)		),		'&amp; # x 0 D ;',CHAR(13) + CHAR(10)	)--SELECT @SQLExec pr_Index @SQLis this correct???</description><pubDate>Tue, 20 Nov 2012 04:49:34 GMT</pubDate><dc:creator>OnlyOneRJ</dc:creator></item><item><title>RE: SQL JOBS Not Functioning</title><link>http://www.sqlservercentral.com/Forums/Topic1386299-1549-1.aspx</link><description>Another way would be to use the following code[code="sql"]DECLARE @SQL NVARCHAR(MAX)SELECT @SQL = 	REPLACE(		CAST(			(				SELECT 'USE ' + QUOTENAME(name) +';' + CHAR(13) + CHAR(10) +				'EXECUTE schema.procedure;'+CHAR(13)+CHAR(10)				FROM sys.databases WHERE name NOT IN ('master','msdb','model','tempdb')				FOR XML PATH('')			) AS NVARCHAR(MAX)		),		'&amp; # x 0 D ;',CHAR(13) + CHAR(10)	)--SELECT @SQLEXECUTE sp_executesql @SQL[/code]just remove the spaces between '&amp; # x 0 D ;'</description><pubDate>Tue, 20 Nov 2012 04:37:48 GMT</pubDate><dc:creator>anthony.green</dc:creator></item><item><title>RE: SQL JOBS Not Functioning</title><link>http://www.sqlservercentral.com/Forums/Topic1386299-1549-1.aspx</link><description>Have you made one step for each database that the SP needs to run over?If so:On the job step properties, click advanced. You will then see "On success action" and make sure "go to the next step" is chosen. (You have to do this for each and every step untill the last one)So, when Step1 completes, Step2 will run, when it completes Step3 will run and so on.If not and your using just 1 job step to do it in a "batch" like so:[code="other"]EXEC DB1.dbo.MySP EXEC DB2.dbo.MySP EXEC DB3.dbo.MySP EXEC DB4.dbo.MySP EXEC DB5.dbo.MySP EXEC DB6.dbo.MySP [/code], then as John said your going to need to do some error handling and such.Do you need to ensure that the previous step is successful before the next one runs, or can the next step run even the first one fails?</description><pubDate>Tue, 20 Nov 2012 04:32:35 GMT</pubDate><dc:creator>shellbus</dc:creator></item><item><title>RE: SQL JOBS Not Functioning</title><link>http://www.sqlservercentral.com/Forums/Topic1386299-1549-1.aspx</link><description>Hi Shell,Acccording to John, i have followed the below step(1) Modify the code I posted so that it fits your environment(2) Create a new job(3) Copy and paste the code into the "Command" field(4) Schedule the job to run with the desired frequency and at the desired timesNow how will i confirm myself that the 2nd sp gets executed only after 1st one finishes and so on??U have any idea</description><pubDate>Tue, 20 Nov 2012 04:17:51 GMT</pubDate><dc:creator>OnlyOneRJ</dc:creator></item><item><title>RE: SQL JOBS Not Functioning</title><link>http://www.sqlservercentral.com/Forums/Topic1386299-1549-1.aspx</link><description>Could create a maintenance plan for the steps and just add them in one at a time with a success constraint. Pretty much the same thing as doing it in a job, however there's the handy little success constraint that you can add to ensure the next step doesn't execute until the previous one is successful.</description><pubDate>Tue, 20 Nov 2012 04:02:15 GMT</pubDate><dc:creator>shellbus</dc:creator></item><item><title>RE: SQL JOBS Not Functioning</title><link>http://www.sqlservercentral.com/Forums/Topic1386299-1549-1.aspx</link><description>20 seperate steps is okas of now...But in another Server there are almost more than 100 Db's :w00t:Anyways will test it step by step, incase i have any issues, will write here.. thanks John :-)</description><pubDate>Tue, 20 Nov 2012 03:40:23 GMT</pubDate><dc:creator>OnlyOneRJ</dc:creator></item><item><title>RE: SQL JOBS Not Functioning</title><link>http://www.sqlservercentral.com/Forums/Topic1386299-1549-1.aspx</link><description>That's right, yes.  You might want to test what happens if one command fails - does it abort the whole batch or does it move on to the next command.  If it moves on and that isn't what you want, then you'll either need to include some error handling, or split your job into 20 separate steps.John</description><pubDate>Tue, 20 Nov 2012 03:31:14 GMT</pubDate><dc:creator>John Mitchell-245523</dc:creator></item><item><title>RE: SQL JOBS Not Functioning</title><link>http://www.sqlservercentral.com/Forums/Topic1386299-1549-1.aspx</link><description>Cool John, Thanks Man ;-)I will do it today itself &amp; will let you know tomorrow..Just one question..IF i set the SP pne after other then..The sequence of execution will be one after other???I mean 1st sp excutes &amp; then after it finishes themn only second Sp will execute???</description><pubDate>Tue, 20 Nov 2012 03:27:04 GMT</pubDate><dc:creator>OnlyOneRJ</dc:creator></item><item><title>RE: SQL JOBS Not Functioning</title><link>http://www.sqlservercentral.com/Forums/Topic1386299-1549-1.aspx</link><description>(1) Modify the code I posted so that it fits your environment(2) Create a new job(3) Copy and paste the code into the "Command" field(4) Schedule the job to run with the desired frequency and at the desired timesClearly you're struggling with something, but remember I'm not standing behind you and I can't see your screen, so if there's anything you don't understand, please be very specific about what it is.John</description><pubDate>Tue, 20 Nov 2012 03:21:22 GMT</pubDate><dc:creator>John Mitchell-245523</dc:creator></item><item><title>RE: SQL JOBS Not Functioning</title><link>http://www.sqlservercentral.com/Forums/Topic1386299-1549-1.aspx</link><description>Yes the procedure is same for all database, but John can u let me know the steps by step about setting the jobs?</description><pubDate>Tue, 20 Nov 2012 03:16:13 GMT</pubDate><dc:creator>OnlyOneRJ</dc:creator></item><item><title>RE: SQL JOBS Not Functioning</title><link>http://www.sqlservercentral.com/Forums/Topic1386299-1549-1.aspx</link><description>Not only can you do it one single job, you can do it in one single job step, in the way I suggested above.John</description><pubDate>Tue, 20 Nov 2012 03:00:40 GMT</pubDate><dc:creator>John Mitchell-245523</dc:creator></item><item><title>RE: SQL JOBS Not Functioning</title><link>http://www.sqlservercentral.com/Forums/Topic1386299-1549-1.aspx</link><description>Does the same procedure exist in all 20 databases and does it need any special paramateres to run?</description><pubDate>Tue, 20 Nov 2012 02:59:46 GMT</pubDate><dc:creator>anthony.green</dc:creator></item><item><title>RE: SQL JOBS Not Functioning</title><link>http://www.sqlservercentral.com/Forums/Topic1386299-1549-1.aspx</link><description>how do i set the JOBS one after one..I mean...1st the SP for one DB will be executed &amp; only after that the SP should get executed of rthe second DB &amp; so on....Is this possible to perform the above activity in One Single Job???</description><pubDate>Tue, 20 Nov 2012 02:58:55 GMT</pubDate><dc:creator>OnlyOneRJ</dc:creator></item><item><title>RE: SQL JOBS Not Functioning</title><link>http://www.sqlservercentral.com/Forums/Topic1386299-1549-1.aspx</link><description>I didn't go anywhere.  What is your question?John</description><pubDate>Tue, 20 Nov 2012 02:56:41 GMT</pubDate><dc:creator>John Mitchell-245523</dc:creator></item><item><title>RE: SQL JOBS Not Functioning</title><link>http://www.sqlservercentral.com/Forums/Topic1386299-1549-1.aspx</link><description>john, where did u go:w00t:</description><pubDate>Tue, 20 Nov 2012 02:50:05 GMT</pubDate><dc:creator>OnlyOneRJ</dc:creator></item><item><title>RE: SQL JOBS Not Functioning</title><link>http://www.sqlservercentral.com/Forums/Topic1386299-1549-1.aspx</link><description>Yes John, same to same :-)</description><pubDate>Mon, 19 Nov 2012 04:51:15 GMT</pubDate><dc:creator>OnlyOneRJ</dc:creator></item><item><title>RE: SQL JOBS Not Functioning</title><link>http://www.sqlservercentral.com/Forums/Topic1386299-1549-1.aspx</link><description>Something like this?[code="sql"]EXEC DB1.dbo.MySP EXEC DB2.dbo.MySP EXEC DB3.dbo.MySP EXEC DB4.dbo.MySP EXEC DB5.dbo.MySP EXEC DB6.dbo.MySP EXEC DB7.dbo.MySP EXEC DB8.dbo.MySP EXEC DB9.dbo.MySP EXEC DB10.dbo.MySPEXEC DB11.dbo.MySP EXEC DB12.dbo.MySP EXEC DB13.dbo.MySP EXEC DB14.dbo.MySP EXEC DB15.dbo.MySP EXEC DB16.dbo.MySP EXEC DB17.dbo.MySP EXEC DB18.dbo.MySP EXEC DB19.dbo.MySP EXEC DB20.dbo.MySP [/code]John</description><pubDate>Mon, 19 Nov 2012 04:47:58 GMT</pubDate><dc:creator>John Mitchell-245523</dc:creator></item><item><title>SQL JOBS Not Functioning</title><link>http://www.sqlservercentral.com/Forums/Topic1386299-1549-1.aspx</link><description>SQL JOBS Not Functioning :w00t:I have Stored procedure &amp; that stored procedure needs to be executed on 20 Databases daily,Currently i am doing it manually..I tried setting the Jobs on SQL but it only executes the SP for One database &amp; not for all DB's.... :w00t:how do i set the JOBS one after one..I mean...1st the SP for one DB will be executed &amp; only after that the SP should get executed of rthe second DB &amp; so on....:crazy: somehow i am not getting the exact steps or i may be missing something.. please help me</description><pubDate>Mon, 19 Nov 2012 04:39:29 GMT</pubDate><dc:creator>OnlyOneRJ</dc:creator></item></channel></rss>