IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[dbo].[mps_newdepart_std]') AND type = 'P')
DROP PROCEDURE [dbo].[mps_newdepart_std]
GO
CREATE procedure [dbo].[mps_newdepart_std] 
@cmpid int ,
@dp_code varchar(20) ,
@dp_depart nvarchar(50) as
begin
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
declare @dpid int 
select top 1 @dpid = dp_id from mps_depart_base where dp_cmpid=@cmpid and dp_code=@dp_code and dp_isgroup=1 
set @dpid = isnull(@dpid , 0 ) 
if (@dpid=0) 
begin
insert into mps_depart_base(dp_cmpid , dp_code , dp_depart , dp_isgroup) 
values(@cmpid  ,  @dp_code , @dp_depart,1) 
select top 1 @dpid = dp_id from mps_depart_base where dp_cmpid=@cmpid and dp_code=@dp_code and dp_isgroup=1 
select * from mps_depart_base where dp_id=@dpid 
end else 
begin
select 0 none where 0=1 
end 
end