Example Stored Procedure: DELETE

/***********************************************************************************************/
PRINT 'DeleteRGConversation';
/***********************************************************************************************/
GO
IF EXISTS (SELECT 1 FROM INFORMATION_SCHEMA.ROUTINES WHERE ROUTINE_NAME = N'DeleteRGConversation' AND ROUTINE_TYPE = N'PROCEDURE' AND ROUTINE_SCHEMA = N'dbo')
    DROP PROCEDURE dbo.DeleteRGConversation
GO
CREATE PROCEDURE dbo.DeleteRGConversation (
    @UserID         int,
    @ConversationID int
) AS
/*
    Marks a conversation with a user as deleted.
*/
BEGIN
    SET NOCOUNT ON

    DECLARE @error     int
    DECLARE @list      varchar(512)
    DECLARE @rowcount  int
    DECLARE @spName    sysname

    SELECT @spName = Object_Name(@@ProcID)

   
UPDATE dbo.RGConversation
    SET Status = 'DELETED'
    WHERE UserID         = @UserID
      AND ConversationID = @ConversationID

    SELECT
        @error    = @@error,
        @rowcount = @@rowcount

    IF @error <> 0 OR @rowcount <> 1 BEGIN
        EXEC dbo.TagValueList @list OUTPUT, 'ConversationID', @ConversationID
 
        IF @error <> 0 BEGIN
            RAISERROR(990003, 16, 1, @error, @spName, 'RGConversation', @list)
            RETURN(@error)
        END
        ELSE IF @rowcount <> 1 BEGIN
            RAISERROR(990007, 16, 1, @spName, 'RGConversation', @rowcount, @list) WITH SETERROR
            RETURN(@@error)
        END
    END

    RETURN(0)
END
GO