text: if exists (select * from INFORMATION_SCHEMA.ROUTINES where ROUTINE_NAME = 'spMODULES_TAB_ORDER_MoveUp' and ROUTINE_TYPE = 'PROCEDURE')
  	Drop Procedure dbo.spMODULES_TAB_ORDER_MoveUp;
  GO
  
  
  /**********************************************************************************************************************
   * Copyright (C) 2005-2022 SplendidCRM Software, Inc. 
   * MIT License
   * 
   * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation 
   * files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, 
   * modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software 
   * is furnished to do so, subject to the following conditions:
   * 
   * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
   * 
   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 
   * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 
   * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR 
   * IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
   *********************************************************************************************************************/
  -- 04/21/2009 Paul.  Correct any ordering problems before moving. 
  Create Procedure dbo.spMODULES_TAB_ORDER_MoveUp
  	( @ID               uniqueidentifier
  	, @MODIFIED_USER_ID uniqueidentifier
  	)
  as
    begin
  	set nocount on
  	
  	declare @SWAP_ID    uniqueidentifier;
  	declare @TAB_ORDER  int;
  	if exists(select * from MODULES where ID = @ID and DELETED = 0) begin -- then
  		-- 04/21/2009 Paul.  Correct any ordering problems before moving. 
  		exec dbo.spMODULES_TAB_ORDER_Reorder @MODIFIED_USER_ID;
  
  		-- BEGIN Oracle Exception
  			select @TAB_ORDER = TAB_ORDER
  			  from MODULES
  			 where ID          = @ID
  			   and DELETED     = 0;
  		-- END Oracle Exception
  		-- 01/04/2006 Paul.  TAB_ORDER 0 is reserved.  Don't allow decrease below 1. 
  		if @TAB_ORDER > 1 begin -- then
  			-- BEGIN Oracle Exception
  				select @SWAP_ID   = ID
  				  from MODULES
  				 where TAB_ORDER = @TAB_ORDER - 1
  				   and DELETED    = 0;
  			-- END Oracle Exception
  			-- Moving up actually means decrementing the order value. 
  			if dbo.fnIsEmptyGuid(@SWAP_ID) = 0 begin -- then
  				-- BEGIN Oracle Exception
  					update MODULES
  					   set TAB_ORDER       = TAB_ORDER - 1
  					     , DATE_MODIFIED    = getdate()
  					     , DATE_MODIFIED_UTC= getutcdate()
  					     , MODIFIED_USER_ID = @MODIFIED_USER_ID
  					 where ID               = @ID;
  				-- END Oracle Exception
  				-- BEGIN Oracle Exception
  					update MODULES
  					   set TAB_ORDER       = TAB_ORDER + 1
  					     , DATE_MODIFIED    = getdate()
  					     , DATE_MODIFIED_UTC= getutcdate()
  					     , MODIFIED_USER_ID = @MODIFIED_USER_ID
  					 where ID               = @SWAP_ID;
  				-- END Oracle Exception
  			end -- if;
  		end -- if;
  	end -- if;
    end
  GO
  
  Grant Execute on dbo.spMODULES_TAB_ORDER_MoveUp to public;
  GO
  
  