May 29, 2016 at 8:38 am
I have stored procedure calling another stored procedure consider SP1 calling SP2,in SP2 i am getting exception which SP2 it has to stop exeucting then returning to SP1 also by calling the exception handling part of SP1..but in my SP it is still executing remaining part of SP1 , trying with throws(which available in SQL Server 2012) but i am using SQL Server 2008..
May 29, 2016 at 4:55 pm
This was removed by the editor as SPAM
May 31, 2016 at 8:17 am
In SQL 2008, you would use RAISERROR rather than THROW. RAISERROR is being deprecated, so you should use THROW if you are on SQL 2012 or higher.
Drew
PS: If you are using SQL2008, you should have posted this in a 2008 forum rather than a SQL2014 forum.
J. Drew Allen
Business Intelligence Analyst
Philadelphia, PA
May 31, 2016 at 8:43 am
Try...Catch can do what you need.
Example:
CREATE PROC dbo.Proc2 (@Input_in VARCHAR(100))
AS
SET NOCOUNT ON;
RAISERROR('Proc2 failed', 16, 1);
SELECT
@Input_in;
GO
CREATE PROC dbo.Proc1
AS
SET NOCOUNT ON;
BEGIN TRY;
EXEC dbo.Proc2 @Input_in = 'Hello world';
END TRY
BEGIN CATCH
SELECT
ERROR_MESSAGE();
END CATCH;
GO
EXEC dbo.Proc1;
- Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
Property of The Thread
"Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon
May 31, 2016 at 9:01 am
I wouldn't necessarily throw an error, but you certainly could. I would tend to have an output or return param to indicate something.
I know RAISERROR is deprecated, but I doubt this will ever go away. I like RAISEERROR in some cases, THROW in others. I'd like to see THROW improved to handle some of the RAISERROR functionality.
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply