Re: RAISERROR Behaviour
From: Paul Hatcher (phatcher_at_spamless.cix.co.uk)
Date: 05/01/04
- Next message: Aaron Bertrand [MVP]: "Re: SQL Server tablesize"
- Previous message: sean: "SQL Server tablesize"
- Messages sorted by: [ date ] [ thread ]
Date: Sat, 1 May 2004 10:45:59 +0100
Dan
Thanks for that - I wasn't acquiring the return code of the called stored
procedure, i.e. I was treating RAISERROR as if it raised an exception and an
error number.
Regards
Paul
"Dan Guzman" <danguzman@nospam-earthlink.net> wrote in message
news:eDD2g0RLEHA.644@tk2msftngp13.phx.gbl...
> To add to the response by Vyas, here's an example that returns the error
> number to the calling proc:
>
> CREATE PROC B
> @P1 int,
> @P2 int
> AS
> DECLARE @Result int, @LastError int
> SET @Result = @P1/@P2
> SELECT @LastError = @@ERROR
> IF @LastError <> 0 GOTO Done
> --do other stuff
> Done:
> RETURN @LastError
> GO
>
> CREATE PROC A
> AS
> DECLARE @ReturnCode int, @Msg varchar(100)
> EXEC @ReturnCode = B 1, 0
> IF @ReturnCode <> 0
> BEGIN
> SET @Msg = 'B Failed'
> RAISERROR (@Msg, 16, 1)
> END
> GO
>
> EXEC A
>
> --
> Hope this helps.
>
> Dan Guzman
> SQL Server MVP
>
> "Paul Hatcher" <phatcher@spamless.cix.co.uk> wrote in message
> news:eOmN6cRLEHA.268@TK2MSFTNGP10.phx.gbl...
> > I have two SPs A and B, with A calling B. What I want is for A to stop
> > processing if the call to B fails so I have code in A like
> >
> > EXEC dbo.B @P1, @P2
> > IF @@ERROR<> 0
> > BEGIN
> > SET @Msg = 'B Failed'
> > RAISERROR @Msg, 16, 1
> > END
> >
> > The problem is that B is raising it's error (same as above severity 16)
> but
> > @@ERROR is reporting 0 and so A does not terminate - what am I doing
> wrong?
> >
> > Regards
> >
> > Paul
> >
> >
>
>
- Next message: Aaron Bertrand [MVP]: "Re: SQL Server tablesize"
- Previous message: sean: "SQL Server tablesize"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|