IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[dbo].[mps_g_1branch_shop]') AND type = 'P')
DROP PROCEDURE [dbo].[mps_g_1branch_shop]
GO
--选择当前分公司门店员工 
CREATE procedure [dbo].[mps_g_1branch_shop](
@cmpid int,
@mybcid int ,
@key nvarchar(100),
@dkey1 nvarchar(50),
@dkey2 nvarchar(50),
@dkey3 nvarchar(50) 
)
as 
begin
-- 返回部门名称
set nocount on
if(@key='_none_') set  @key = ''
if(@dkey1='_none_') set  @dkey1 = ''
if(@dkey2='_none_') set  @dkey2 = ''
if(@dkey3='_none_') set  @dkey3 = ''

select top 400 dp_id ,dp_dpstdid, dp_depart,dp_fullname ,dp_code ,dp_display 
from mps_depart 
where dp_cmpid=@cmpid and (dp_bcid=@mybcid or @mybcid=0) and dp_fullname>'' and dp_depart>''  and dp_isdepart>0 and 
--(
(dp_depart like '%'+@key+'%' )  
--(dp_province like '%'+@key+'%' ) or 
--(dp_municipal like '%'+@key+'%' )or 
--(dp_county like '%'+@key+'%' ) or 
--(dp_location like '%'+@key+'%' ) or 
--(dp_category1 like '%'+@key+'%' ) or 
--(dp_category2 like '%'+@key+'%' ) or 
--(dp_category3 like '%'+@key+'%' ) or 
--(dp_note like '%'+@key+'%' ) or 
--(dp_status like '%'+@key+'%' ) or 
--(dp_manager1 like '%'+@key+'%' ) or 
--(dp_manager2 like '%'+@key+'%' ) or 
--(dp_manager3 like '%'+@key+'%' ) or 
--(dp_manager3 like '%'+@key+'%' ) or 
--(dp_manager4 like '%'+@key+'%' ) or 
--(dp_manager6 like '%'+@key+'%' ) 
--) 
and  (dp_province=@dkey1 or @dkey1 = '')
and  (dp_municipal=@dkey2 or @dkey2 = '')
and  (dp_county=@dkey3 or @dkey3 = '')

order by  dp_order , dp_level 
set nocount off
end