IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[dbo].[mps_update_account_item_order]') AND type = 'P')
DROP PROCEDURE [dbo].[mps_update_account_item_order]
GO
create proc [dbo].[mps_update_account_item_order]
(
    @ai_id int ,
    @ai_order int 
)
as
begin
    set nocount on
    declare @cmpid int;
    select @cmpid = ai_cmpid from mps_account_item where ai_id = @ai_id
    
    update mps_account_item set 
     ai_order =  case when @ai_order = '-999999999' then ai_order else @ai_order end
    where ai_id = @ai_id;
    
    exec mps_update_account_item_info @cmpid;
    
    set nocount off
end