IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[dbo].[mps_delete_depart_shp]') AND type = 'P')
DROP PROCEDURE [dbo].[mps_delete_depart_shp]
GO
create procedure [dbo].[mps_delete_depart_shp]
@cmpid int,
@mydpid int,
@branchid int,
@userdpid int,
@useruid int,
@userotid int
AS
BEGIN
 SET NOCOUNT ON

declare @operation varchar(50)
declare @errorinfo nvarchar(4000) 
declare @result1 varchar(100)
-- Insert statements for procedure here
declare @empcount bigint
set @empcount = 0;
select @empcount = count(*) from mps_depart, mps_employee
where dp_id = cu_dpid and dp_id = @mydpid
if (dbo.mps_sys_checkkeywords('shp.beforecreate,shp.aftercreate',@cmpid,0,'','')=0)   -- 有事件
begin
exec drop_temp_table '#old'
select * into #old from mps_depart where dp_id = @mydpid
end
--门店删除之前
if (dbo.mps_sys_checkkeywords('shp.beforedelete',@cmpid,0,'','')=0) 
begin
exec mps_depart_shpdelete_before @cmpid,@branchid,@userdpid,@useruid,@userotid,@mydpid,@operation output,@errorinfo output
if @operation = 'abort' 
begin
select @operation operation,@errorinfo errorinfo
return 
end
end

if @empcount = 0
begin
DELETE mps_depart WHERE dp_id = @mydpid
set @result1 = 'ok'
end
else set @result1 = @empcount

select @result1 result1
--门店删除之后
if (dbo.mps_sys_checkkeywords('shp.afterdelete',@cmpid,0,'','')=0) 
begin
exec mps_depart_shpdelete_after @cmpid,@branchid,@userdpid,@useruid,@userotid,@mydpid
end

SET NOCOUNT Off

END