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,@qry_whsj1 varchar(512)
,@qry_whsj2 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_creator varchar(50),
    ord_wlxd int,
    ord_dgj int,
    ord_yyy int,
    ord_jj int,
    ord_count int,
    ord_ycj int
)


insert into #temp(tableid,ord_creator,ord_wlxd,ord_dgj,ord_yyy,ord_jj,ord_count)
select 'tb_report1' tableid, ord_creator,
        COUNT(case when ord_whzt = '未联系到' then
                 ord_creator
             end) as ord_wlxd,
         COUNT(case when ord_whzt = '待跟进' then
                 ord_creator
             end) as ord_dgj,
         COUNT(case when ord_whzt = '已预约' then
                 ord_creator
             end) as ord_yyy,
         COUNT(case when ord_whzt = '拒绝' then
                 ord_creator
             end) as ord_jj,
         count(ord_creator) ord_count
from order_239
where ord_whsj >= @qry_whsj1 + ' 00:00:00'
and ord_whsj <= @qry_whsj2 + ' 23:59:59'
and ord_createdpid =  @userdpid
--and ord_status in ('外呼跟进','预约成功')
and charindex('临',ord_no) = 0
group by ord_creator
order by ord_creator

update #temp set ord_ycj = (select count(ord_creator) from order_239
where ord_cjsj >= @qry_whsj1 + ' 00:00:00'
and ord_cjsj <= @qry_whsj2 + ' 23:59:59'
and ord_createdpid =  @userdpid
and charindex('临',ord_no) = 0
and #temp.ord_creator = order_239.ord_creator
)

select * from #temp







END