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