Hi All,
I need check if one of thise SP had error.
EXEC gerar_dnum_sp @.dnum OUTPUT
EXEC gerar_auto_sp @.auto OUTPUT
EXEC gerar_aute_sp @.dnum, @.auto, @.aute OUTPUT
Then I did this:
EXEC gerar_dnum_sp @.dnum OUTPUT
IF @.@.ERROR <> 0
BEGIN
...
END
EXEC gerar_auto_sp @.auto OUTPUT
IF @.@.ERROR <> 0
BEGIN
...
END
EXEC gerar_aute_sp @.dnum, @.auto, @.aute OUTPUT
IF @.@.ERROR <> 0
BEGIN
...
END
But I need 3 IF @.@.ERROR <> 0..., i would like know if have way to check all
in one time.
like this:
EXEC gerar_dnum_sp @.dnum OUTPUT
EXEC gerar_auto_sp @.auto OUTPUT
EXEC gerar_aute_sp @.dnum, @.auto, @.aute OUTPUT
IF(error in same one)
BEGIN
do same thing
END
Thanks to helpOn Sun, 13 Nov 2005 21:45:21 -0200, ReTF wrote:
(snip)
>But I need 3 IF @.@.ERROR <> 0..., i would like know if have way to check al
l
>in one time.
>like this:
>EXEC gerar_dnum_sp @.dnum OUTPUT
>EXEC gerar_auto_sp @.auto OUTPUT
>EXEC gerar_aute_sp @.dnum, @.auto, @.aute OUTPUT
>IF(error in same one)
>BEGIN
>do same thing
>END
>Thanks to help
Hi ReTF,
You'll have to do SOME work in between the calls, even though you don't
need to cpopy the complete error handling three times.
Most simple:
DECLARE @.err1 int, @.err2 int, @.err3 int
EXEC gerar_dnum_sp @.dnum OUTPUT
SET @.err1 = @.@.ERROR
EXEC gerar_auto_sp @.auto OUTPUT
SET @.err2 = @.@.ERROR
EXEC gerar_aute_sp @.dnum, @.auto, @.aute OUTPUT
SET @.err3 = @.@.ERROR
IF @.err1 <> 0 OR @.err2 <> 0 OR @.err3 <> 0
BEGIN
...
END
Or, better yet because you mostly don't want to keep on executing code
once an error is found:
DECLARE @.err int
EXEC gerar_dnum_sp @.dnum OUTPUT
SET @.err = @.@.ERROR
IF @.err = 0
BEGIN
EXEC gerar_auto_sp @.auto OUTPUT
SET @.err = @.@.ERROR
END
IF @.err = 0
BEGIN
EXEC gerar_aute_sp @.dnum, @.auto, @.aute OUTPUT
SET @.err = @.@.ERROR
END
IF @.err <> 0
BEGIN
...
END
Best, Hugo
--
(Remove _NO_ and _SPAM_ to get my e-mail address)|||Hello,
You may use the return status:
DECLARE @.retstat1 int, @.retstat2 int, @.retstat3 int
DECLARE @.dnum int, @.auto int, @.aute int
EXEC @.retstat1=gerar_dnum_sp @.dnum OUTPUT
EXEC @.retstat2=gerar_auto_sp @.auto OUTPUT
EXEC @.retstat3=gerar_aute_sp @.dnum, @.auto, @.aute OUTPUT
if @.retstat1<>0 or @.retstat2<>0 or @.retstat3<>0
begin
print 'error'
end
I hope the information is helpful.
Sophie Guo
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
========================================
=============
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
========================================
=============
This posting is provided "AS IS" with no warranties, and confers no rights.|||Hi,
I did see
BEGIN TRY ...
I think that this is good to do what I need.
See:
BEGIN TRY
EXEC gerar_dnum_sp @.dnum OUTPUT
EXEC gerar_auto_sp @.auto OUTPUT
EXEC _aute_sp @.dnum, @.auto, @.aute OUTPUTTRY
--and more...
END TRY
BEGIN CATCH
-- if error do samething here
END CATH
What you think?
Thanks
"Sophie Guo [MSFT]" <v-sguo@.online.microsoft.com> wrote in message
news:8q12SPP6FHA.2536@.TK2MSFTNGXA02.phx.gbl...
> Hello,
> You may use the return status:
> DECLARE @.retstat1 int, @.retstat2 int, @.retstat3 int
> DECLARE @.dnum int, @.auto int, @.aute int
> EXEC @.retstat1=gerar_dnum_sp @.dnum OUTPUT
> EXEC @.retstat2=gerar_auto_sp @.auto OUTPUT
> EXEC @.retstat3=gerar_aute_sp @.dnum, @.auto, @.aute OUTPUT
> if @.retstat1<>0 or @.retstat2<>0 or @.retstat3<>0
> begin
> print 'error'
> end
> I hope the information is helpful.
> Sophie Guo
> Microsoft Online Partner Support
> Get Secure! - www.microsoft.com/security
> ========================================
=============
> When responding to posts, please "Reply to Group" via your newsreader so
> that others may learn and benefit from your issue.
> ========================================
=============
> This posting is provided "AS IS" with no warranties, and confers no
> rights.
>|||TRY ... CATCH is a good way of doing error handling if you have SQL 2005.
Otherwise, (sql7/2000)
You should put an @.@.ERROR catch after every failable statement within the
stored proc, if the @.@.ERROR return it to the caller.
Checking @.@.ERROR after the SP wont guarentee you'll catch the error (as it
may have run other commands since the error and reset it back to 0)
EXEC @.re1 = gerar_dnum_sp @.dnum OUTPUT
EXEC @.re2 = gerar_auto_sp @.auto OUTPUT
EXEC @.re3 = gerar_aute_sp @.dnum, @.auto, @.aute OUTPUTTRY
IF ( @.re1 != 0 OR @.re2 != 0 OR @.re3 != 0 )
BEGIN
PRINT '...'
END
"ReTF" <re.tf@.newsgroup.nospam> wrote in message
news:eb90wBU6FHA.1148@.tk2msftngp13.phx.gbl...
> Hi,
> I did see
> BEGIN TRY ...
> I think that this is good to do what I need.
> See:
> BEGIN TRY
> EXEC gerar_dnum_sp @.dnum OUTPUT
> EXEC gerar_auto_sp @.auto OUTPUT
> EXEC _aute_sp @.dnum, @.auto, @.aute OUTPUTTRY
> --and more...
> END TRY
> BEGIN CATCH
> -- if error do samething here
> END CATH
>
> What you think?
>
> Thanks
> "Sophie Guo [MSFT]" <v-sguo@.online.microsoft.com> wrote in message
> news:8q12SPP6FHA.2536@.TK2MSFTNGXA02.phx.gbl...
>
Monday, March 19, 2012
Check error question.
Labels:
aute,
auto,
database,
dnum,
error,
exec,
gerar_aute_sp,
gerar_auto_sp,
gerar_dnum_sp,
microsoft,
mysql,
oracle,
outputexec,
server,
sql,
thise
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment