IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[dbo].[report_44_data]') AND type = 'P')
DROP PROCEDURE [dbo].[report_44_data]
GO
CREATE PROCEDURE report_44_data
@cmpid int,@branchid int,@userdpid int,@userotid int,@useruid int,@tableid varchar(8000),@objids varchar(8000),@pagesize int,@qry_date1 varchar(512)
,@qry_date2 varchar(512)

AS
BEGIN
 set nocount on 

declare @dataIds table(objid int)
if @objids!='_NONE' and @objids!='_none_' and @objids!='' 
insert into @dataIds(objid)
select value from dbo.fn_split_int(@objids)
create table #tempt(
tableid varchar(10),
ord_gs varchar(50),--公司名称
ord_mds bigint ,--门店个数
ord_wgmds bigint ,--违规门店数
ord_wgmdzb varchar(50),--违规门店占比
ord_wgmdcs bigint,--通报违规次数
ord_dzwgpl varchar(50),--单店违规发生频率
ord_bcid int --公司id
)
insert into #tempt(tableid,ord_gs,ord_bcid)select 'tb_report1',bc_company,bc_id from mps_branch

insert into #tempt(tableid,ord_gs,ord_bcid)select 'tb_report1','天府新区',7

update #tempt set ord_mds = (select count(10) from mps_depart 
where dp_isdepart = 1 
and (dp_status ='启用' or dp_status = '新开店')
and dp_bcid = ord_bcid
)
where  ord_bcid != 7

update #tempt set ord_mds =(select count(10) from mps_depart 
where dp_fullname like '%天府新区%'
and (dp_status ='启用' or dp_status = '新开店')
and dp_isdepart = 1)
where  ord_bcid = 7

update #tempt set ord_mds = ord_mds - (select ord_mds from #tempt 
where ord_bcid = 7) 
where ord_bcid = 18


update #tempt set ord_wgmds = (select count(distinct ord_dpmc) from order_272
where #tempt.ord_bcid = ord_zbxsyfgsid 
and ord_no not like '%临%'
and ord_status != '已作废'
and ord_date >= @qry_date1 + ' 00:00:00' 
and ord_date <= @qry_date2 + ' 23:59:59')


update #tempt set ord_wgmds = (select count(distinct ord_dpmc) 
from order_272 
where ord_dpmc like '%天府新区%' 
and ord_no not like '%临%'
and ord_status != '已作废'
and ord_date >= @qry_date1 + ' 00:00:00' 
and ord_date <= @qry_date2 + ' 23:59:59'
)
where  ord_bcid = 7

update #tempt set ord_wgmds = ord_wgmds - (select ord_wgmds from #tempt 
where ord_bcid = 7) 
where ord_bcid = 18

update #tempt set  ord_wgmdzb=  convert(varchar,cast((ord_wgmds*1.00/ord_mds)*100 as decimal(18,0)))+'%'  


update #tempt set ord_wgmdcs = (select count(10) from order_272 
where #tempt.ord_bcid = ord_zbxsyfgsid 
and  ord_no not like '%临%'
and ord_status != '已作废'
and ord_date >= @qry_date1 + ' 00:00:00' 
and ord_date <= @qry_date2 + ' 23:59:59') 


update #tempt set ord_wgmds = ord_wgmds - (select ord_wgmds from #tempt 
where ord_bcid = 7) 
where ord_bcid = 18

update #tempt set ord_wgmdcs = (select count(10) 
from order_272 
where ord_no not like '%临%'
and ord_status != '已作废' 
and ord_dpmc like '%天府新区%'
and ord_date >= @qry_date1 + ' 00:00:00' 
and ord_date <= @qry_date2 + ' 23:59:59')
 where ord_bcid = 7


update #tempt set ord_wgmdcs = ord_wgmdcs - (select ord_wgmdcs from #tempt 
where ord_bcid = 7) 
where ord_bcid = 18

update #tempt set  ord_dzwgpl =  convert(varchar,cast((ord_wgmdcs*1.00/ord_mds)*100 as decimal(18,0)))+'%' 


select * from #tempt  

END