IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[dbo].[report_2_data]') AND type = 'P')
DROP PROCEDURE [dbo].[report_2_data]
GO
CREATE PROCEDURE report_2_data
@cmpid int,@branchid int,@userdpid int,@userotid int,@useruid int,@tableid varchar(8000),@objids varchar(8000),@pagesize int,@qdkordid 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)
declare @t table(id bigint primary key identity(1,1), [推送类型] varchar(100),[片区] varchar(100),[报名人数] int ,[签到人数] int)
declare @t1 table( [推送类型1] varchar(100),[片区1] varchar(100),[签到人数1] int)

insert into @t([推送类型],[片区],报名人数)
select [推送类型],[片区],COUNT(10) 报名人数 from 
(
select  distinct 
convert(varchar(100),ord2_date,120) [日期] --datetime
,hy.ord_tsdx [推送类型]
,da.ord_rzbm [片区]
,ord2_gh [工号] --string
,ord2_xm [姓名] --string
,ord2_szdp [所在店铺] --string
,ord2_sfzh [身份证号] --string
,ord2_sjh [手机号] --string
,ord2_sfzs [是否住宿] --string
,ord2_sfbm [是否报名] --string
,ord2_qdcs [签到次数] --integer
,ord2_sfch [是否参会] --string
,case when ord2_dksj = '1900-01-01 00:00:00.000' then '' else  convert(nvarchar(100),ord2_dksj,120) end  [打卡时间] --datetime
from  order_153_102 mx ,order_153 hy ,order_40 da
where hy.ord_id = ord2_ordid 
and ord2_gh = da.ord_gh
and ord2_sfbm ='是'
and da.ord_rzbm<>''
and hy.ord_id = @qdkordid
) x
group by [推送类型],[片区] 
order by [推送类型],[片区] 


insert into @t1([推送类型1],[片区1],签到人数1)
select [推送类型],[片区],COUNT(10) 签到人数 from 
(
select  distinct 
convert(varchar(100),ord2_date,120) [日期] --datetime
,hy.ord_tsdx [推送类型]
,da.ord_rzbm [片区]
,ord2_gh [工号] --string
,ord2_xm [姓名] --string
,ord2_szdp [所在店铺] --string
,ord2_sfzh [身份证号] --string
,ord2_sjh [手机号] --string
,ord2_sfzs [是否住宿] --string
,ord2_sfbm [是否报名] --string
,ord2_qdcs [签到次数] --integer
,ord2_sfch [是否参会] --string
,case when ord2_dksj = '1900-01-01 00:00:00.000' then '' else  convert(nvarchar(100),ord2_dksj,120) end  [打卡时间] --datetime
from  order_153_102 mx ,order_153 hy ,order_40 da
where hy.ord_id = ord2_ordid 
and ord2_gh = da.ord_gh
and ord2_sfbm ='是'
and ord2_sfch = '是' 
and da.ord_rzbm<>''
and hy.ord_id = @qdkordid
) x
group by [推送类型],[片区]

update @t 
set 签到人数 = 签到人数1
from @t1
where [推送类型] = [推送类型1]
and [片区] = [片区1]

select 'tb_report1' tableid,[推送类型] ord_tslx ,
        [片区] ord_pq,
        isnull([报名人数],0) [ord_bmrs], 
        isnull([签到人数],0) [ord_qdrs]  
from @t

END