Monday, March 12, 2012

How do I force a job to fail ?

Hi
I think this is quite simple, but how do I force a job to fail using a TSQL
command?
I have a job that copies a backup to another server and then it starts
another job that restore the backup. What I'd like to do, is to put a step
in the first job, that e.g. runs RESTORE HEADERONLY FROM DISK=...... and if
this doesn't return the correct value the job should quit with a failure.
Regards
SteenDo a RAISERROR with severity > 10.
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
Blog: http://solidqualitylearning.com/blogs/tibor/
"Steen Persson (DK)" <spe@.REMOVEdatea.dk> wrote in message
news:uVV$UWxnFHA.3256@.tk2msftngp13.phx.gbl...
> Hi
> I think this is quite simple, but how do I force a job to fail using a TSQ
L command?
> I have a job that copies a backup to another server and then it starts ano
ther job that restore
> the backup. What I'd like to do, is to put a step in the first job, that e
.g. runs RESTORE
> HEADERONLY FROM DISK=...... and if this doesn't return the correct value
the job should quit with
> a failure.
> Regards
> Steen
>|||why dont you use continue, break in procedure that is getting executed
instead of stopping job on condition.
"Steen Persson (DK)" wrote:

> Hi
> I think this is quite simple, but how do I force a job to fail using a TSQ
L
> command?
> I have a job that copies a backup to another server and then it starts
> another job that restore the backup. What I'd like to do, is to put a step
> in the first job, that e.g. runs RESTORE HEADERONLY FROM DISK=...... and
if
> this doesn't return the correct value the job should quit with a failure.
> Regards
> Steen
>
>|||R.D wrote:
> why dont you use continue, break in procedure that is getting
> executed instead of stopping job on condition.
>
well...good question. It was just the first idea that came to my mind. If I
"force" the job to fail, I'd get a notification just like if the job was
failing in the "normal" way, so I saw it as the easiest way of doing it.
My next issue (which I thought I knew how to do...) is how I fetch the
result set I get from running "RESTORE HEADERONLY..." so I can evaluate on
e.g. the BackupName field?
Regards
Steen|||> My next issue (which I thought I knew how to do...) is how I fetch the result set I get f
rom
> running "RESTORE HEADERONLY..." so I can evaluate on e.g. the BackupName field?[/
color]
CREATE TABLE r (...)
INSERT INTO r(...)
EXEC('RESTORE HEADERONLY ...')
You can find the structure of the table you need to create, and the overall
technique at
http://www.karaszi.com/SQLServer/ut...ll_in_file.asp.
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
Blog: http://solidqualitylearning.com/blogs/tibor/
"Steen Persson (DK)" <spe@.REMOVEdatea.dk> wrote in message
news:%23ky1olxnFHA.3316@.tk2msftngp13.phx.gbl...
> R.D wrote:
> well...good question. It was just the first idea that came to my mind. If
I "force" the job to
> fail, I'd get a notification just like if the job was failing in the "norm
al" way, so I saw it as
> the easiest way of doing it.
> My next issue (which I thought I knew how to do...) is how I fetch the res
ult set I get from
> running "RESTORE HEADERONLY..." so I can evaluate on e.g. the BackupName
field?
> Regards
> Steen
>

No comments:

Post a Comment