Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase ««123»»

SQL JOBS Not Functioning Expand / Collapse
Author
Message
Posted Tuesday, November 20, 2012 3:27 AM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Wednesday, March 12, 2014 12:13 AM
Points: 258, Visits: 690
Cool John, Thanks Man
I will do it today itself & 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 & then after it finishes themn only second Sp will execute???








************************************
Every Dog has a Tail !!!!!
Post #1386787
Posted Tuesday, November 20, 2012 3:31 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Today @ 9:10 AM
Points: 5,437, Visits: 10,129
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
Post #1386790
Posted Tuesday, November 20, 2012 3:40 AM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Wednesday, March 12, 2014 12:13 AM
Points: 258, Visits: 690
20 seperate steps is okas of now...
But in another Server there are almost more than 100 Db's

Anyways will test it step by step, incase i have any issues, will write here.. thanks John








************************************
Every Dog has a Tail !!!!!
Post #1386798
Posted Tuesday, November 20, 2012 4:02 AM


Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Wednesday, July 10, 2013 2:14 AM
Points: 5, Visits: 79
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.
Post #1386808
Posted Tuesday, November 20, 2012 4:17 AM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Wednesday, March 12, 2014 12:13 AM
Points: 258, Visits: 690
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 times

Now how will i confirm myself that the 2nd sp gets executed only after 1st one finishes and so on??
U have any idea








************************************
Every Dog has a Tail !!!!!
Post #1386813
Posted Tuesday, November 20, 2012 4:32 AM


Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Wednesday, July 10, 2013 2:14 AM
Points: 5, Visits: 79
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:
EXEC DB1.dbo.MySP 
EXEC DB2.dbo.MySP
EXEC DB3.dbo.MySP
EXEC DB4.dbo.MySP
EXEC DB5.dbo.MySP
EXEC DB6.dbo.MySP

, 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?

Post #1386827
Posted Tuesday, November 20, 2012 4:37 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Yesterday @ 4:10 AM
Points: 5,221, Visits: 5,119
Another way would be to use the following code

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)
),
'& # x 0 D ;',CHAR(13) + CHAR(10)
)
--SELECT @SQL
EXECUTE sp_executesql @SQL

just remove the spaces between '& # x 0 D ;'




Want an answer fast? Try here
How to post data/code for the best help - Jeff Moden
Need a string splitter, try this - Jeff Moden
How to post performance problems - Gail Shaw
CrossTabs-Part1 & Part2 - Jeff Moden
SQL Server Backup, Integrity Check, and Index and Statistics Maintenance - Ola Hallengren
Managing Transaction Logs - Gail Shaw
Troubleshooting SQL Server: A Guide for the Accidental DBA - Jonathan Kehayias and Ted Krueger

Post #1386830
Posted Tuesday, November 20, 2012 4:49 AM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Wednesday, March 12, 2014 12:13 AM
Points: 258, Visits: 690
thanks Shell.. will try to implement it

Anthony - 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)
),
'& # x 0 D ;',CHAR(13) + CHAR(10)
)
--SELECT @SQL

Exec pr_Index @SQL


is this correct???








************************************
Every Dog has a Tail !!!!!
Post #1386838
Posted Tuesday, November 20, 2012 4:53 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Yesterday @ 4:10 AM
Points: 5,221, Visits: 5,119
Use my code, the only thing you need to do is to replace the the text schema.procedure with the name of your procedure eg. dbo.thisismyprocedure

Then remove the spaces between the '& # x 0 D ;'

The last step should be exec sp_executesql @sql do not change that line.




Want an answer fast? Try here
How to post data/code for the best help - Jeff Moden
Need a string splitter, try this - Jeff Moden
How to post performance problems - Gail Shaw
CrossTabs-Part1 & Part2 - Jeff Moden
SQL Server Backup, Integrity Check, and Index and Statistics Maintenance - Ola Hallengren
Managing Transaction Logs - Gail Shaw
Troubleshooting SQL Server: A Guide for the Accidental DBA - Jonathan Kehayias and Ted Krueger

Post #1386841
Posted Tuesday, November 20, 2012 4:56 AM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Wednesday, March 12, 2014 12:13 AM
Points: 258, Visits: 690
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???







************************************
Every Dog has a Tail !!!!!
Post #1386845
« Prev Topic | Next Topic »

Add to briefcase ««123»»

Permissions Expand / Collapse