IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[dbo].[report_31_data]') AND type = 'P')
DROP PROCEDURE [dbo].[report_31_data]
GO
CREATE PROCEDURE report_31_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 #temp (
     tableid varchar(10),
     ord_xmmc varchar(500),
 ord_jclx varchar(100),--检查类型
     ord_bhgs int DEFAULT 0,--不合格数
 ord_sywt int DEFAULT 0,--所有问题数
ord_lz decimal(18,2) default 0.0 --所有问题内占   
 )


insert into #temp(ord_jclx,ord_xmmc,ord_bhgs)
select  ord2_jclx,ord2_lrbz,count (*) as '次数'  from order_248_2
where ord2_date >= @qry_date1 + ' 00:00:00' and  ord2_date <= @qry_date2 + ' 23:59:59'
 and ord2_jclx = '日常检查' and ord2_jcqk='不合格' group by ord2_lrbz,ord2_jclx order by ord2_jclx,'次数' desc 
insert into #temp(ord_jclx,ord_xmmc,ord_bhgs)
select  ord2_jclx,ord2_lrbz,count (*) as '次数'  from order_248_2
where ord2_date >= @qry_date1 + ' 00:00:00' and  ord2_date <= @qry_date2 + ' 23:59:59'
 and ord2_jclx = '夜间检查' and ord2_jcqk='不合格' group by ord2_lrbz,ord2_jclx order by ord2_jclx,'次数' desc 
update #temp set tableid = 'tb_report1'
update #temp set ord_sywt = (select  count (*)  from order_248_2 
where ord2_date >= @qry_date1 + ' 00:00:00' and  ord2_date <= @qry_date2 + ' 23:59:59'
 and  ord2_jcqk='不合格' )
update #temp set ord_lz = CONVERT(decimal(18, 2),ord_bhgs * 1.0 / ord_sywt)

select * from #temp
END