Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
SP Builder Utility
Message
 
To
29/12/2000 16:13:20
George Simon
GS Data Technologies, LLC
Cincinnati, Ohio, United States
General information
Forum:
Visual FoxPro
Category:
Client/server
Miscellaneous
Thread ID:
00457879
Message ID:
00457951
Views:
20
Will SQL Server set @@ERROR if @nCommunID does not exist in the table?

>Here's an example of a DELETE SP that checks for a foreign key constraint violation and then any other errors:
>
>CREATE PROCEDURE usp_community_delete
>@nCommunID int,
>@nResultCode int=0 OUTPUT
>AS
>
>DECLARE @nError int
>
>-- Delete the row.
>DELETE FROM community WHERE communid = @nCommunID
>SET @nError = @@ERROR
>
>-- Determine if a foreign key constraint has been violated.
>IF @nError = 547
> BEGIN
> RAISERROR('This community is already in use and cannot be deleted.',11,1)
> GOTO err_handler
> END
>
>-- Check for any other non-fatal errors.
>IF @nError <> 0
> BEGIN
> RAISERROR('Unable to delete this community.',11,1)
> GOTO err_handler
> END
>
>-- The DELETE was successful.
>RETURN @nResultCode
>
>-- Error Handler
>err_handler:
>SET @nResultCode = -1003
>RETURN @nResultCode
>
>
>I typically check the @@ERROR function after every SQL statement. If an error occurs, the message can can be retrieved using AERROR() in my data service object (have to do some parsing.)
Chris McCandless
Red Sky Software
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform