IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[dbo].[mps_up_account_branch]') AND type = 'P')
DROP PROCEDURE [dbo].[mps_up_account_branch]
GO
CREATE proc [dbo].[mps_up_account_branch] 
@bcid int,
@aiid bigint
as
begin
set nocount on
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
declare @id int;
select @id = aib_id from mps_account_branch
where  aib_aiid = @aiid and aib_bcid =@bcid

if(@id>0) 
begin
update mps_account_branch set aib_use = 0 where aib_id = @id 
end
else
begin
insert into mps_account_branch values(@bcid,@aiid,0,1,0)
select @@IDENTITY as aib_id
end
set nocount off
end