Thursday 18 April 2013

spDelete

USE [DineShore]
GO
/****** Object:  StoredProcedure [dbo].[spDesigantion_Delete]    Script Date: 04/19/2013 11:18:31 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/* ==========================================
-- Purpose        : To Delete Designation Details
-- Module        : DineShore Admin
-- Created By    : Sumesh
-- Created On    : 10- Feb - 2012 02:21 PM
-- Execute        : DECLARE @P_Ret_Value INT
                  EXEC [spDepartment_Delete] 5, @P_Ret_Value OUTPUT
                  SELECT @P_Ret_Value
-- Return Values: 1 : Deleted Successfully
                  0 : Record Not found/ Already Deleted
                 -1 : If Any Sql error occur
  ==========================================*/

ALTER PROC [dbo].[spDesigantion_Delete]
             (@P_Id  INT
             ,@P_Ret_Value INT OUTPUT)
AS
SET NOCOUNT ON
BEGIN TRY
    BEGIN TRANSACTION
            -- Check id exists
            IF EXISTS(SELECT [ID] FROM [Designations_Mst]
                    WHERE [ID] =@P_Id )
                BEGIN
                -- ID Exists, then delete the details
                DELETE FROM [Designations_Mst]
                        WHERE [ID] =@P_Id
                -- Delete Success , Set Return value as 1
                SET @P_Ret_Value = 1
                END
            ELSE
                -- if id not exists, then return 0, details already deleted
                SET @P_Ret_Value = 0
    COMMIT TRANSACTION
END TRY
BEGIN CATCH
-- if any excepetion occur set return value as -1
    SET @P_Ret_Value = -1
    ROLLBACK TRANSACTION
END CATCH

No comments:

Post a Comment