IF EXISTS ( SELECT * 
            FROM   sysobjects 
            WHERE  id = object_id(N'dbo.CP_Seg_Menu_Mod_Mover') 
                   and OBJECTPROPERTY(id, N'IsProcedure') = 1 )
BEGIN
    DROP PROCEDURE dbo.CP_Seg_Menu_Mod_Mover
END
GO

CREATE PROCEDURE dbo.CP_Seg_Menu_Mod_Mover @Id_Modulo INT, @Id_Menu INT, @Accion CHAR(1)
AS
BEGIN
SET NOCOUNT ON

DECLARE @Id_Menu_Padre INT

IF @Accion = 'S'
	UPDATE Seg_Menu_Mod SET Orden = Orden - 15 WHERE Id_Menu = @Id_Menu AND Id_Modulo = @Id_Modulo
IF @Accion = 'B'
	UPDATE Seg_Menu_Mod SET Orden = Orden + 15 WHERE Id_Menu = @Id_Menu AND Id_Modulo = @Id_Modulo

SELECT @Id_Menu_Padre = Id_Menu_Padre FROM Seg_Menu_Mod WHERE Id_Menu = @Id_Menu AND Id_Modulo = @Id_Modulo
EXEC CP_Seg_Menu_Mod_Ordenar @Id_Modulo,@Id_Menu_Padre

END

/*
exec CP_Seg_Menu_Mod_Mover 1,46,'S'
exec CP_Seg_Menu_Mod_Mover 1,46,'B'


*/