CREATE PROCEDURE [dbo].[DeleteUser]
-- Add the parameters for the stored procedure here
@original_UserID nvarchar(64) = UserID,
@temp int =0
AS
BEGIN
SELECT @temp = COUNT(*) FROM dbo.Users WHERE ManagerID = @original_UserID
END
BEGIN
IF(@temp>0)
RAISERROR ('This user is manager of other user',
16, -- Severity.
1 -- State.
);
//Error occurred / Terminate the stored procedure
END
BEGIN
SELECT @temp = COUNT(*) FROM dbo.Project WHERE ProjectManagerID = @original_UserID
END
I tried using return but it didn’t work
P/S: I use this stored procedure in a girdview, which is contained in an updatePanel, I dont know this can cause problem or not
RAISERROR will throw an exception to the nearest catch block. So adding exception handling to your code will give the desired effect..
http://msdn.microsoft.com/en-us/library/ms178592(v=sql.90).aspx