if exists(select 1 from sysobjects where name='pr_bossrpt_branchinfo')
  drop procedure pr_bossrpt_branchinfo
go

create procedure pr_bossrpt_branchinfo(@as_operid varchar(4))
as
begin
	declare @branch_no varchar(6)
	select @branch_no = rtrim(ltrim(branch_no)) from t_sys_operator where oper_id = @as_operid
	
	select rtrim(branch_no) as BranchCode, branch_name  as BranchName 
	from t_bd_branch_info
	where (property = '3' or property = '2')
	and (@as_operid='1001' or @branch_no = 'ALL' or 
	branch_no in (select branch_no from t_bd_branch_info where branch_no like @branch_no+'%')
	and ( len(branch_no) != 2) --2位为总部或分公司仓库
	) 
end
go