IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[dbo].[report_38_data]') AND type = 'P')
DROP PROCEDURE [dbo].[report_38_data]
GO
CREATE PROCEDURE report_38_data
@cmpid int,@branchid int,@userdpid int,@userotid int,@useruid int,@tableid varchar(8000),@objids varchar(8000),@pagesize int,@qry_branch varchar(512)
,@qry_store 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 @qrydate varchar(10)
SELECT @qrydate = CONVERT(varchar(10), DATEADD(DAY,-1,GETDATE()) , 120)

create table #temp1 (
    ord_branch varchar(100),
    ord_area varchar(100),
    ord_store varchar(100),
    ord_employee varchar(100),
    ord_ysl decimal(10,2) default 0,
    ord_wcl decimal(10,2) default 0,
    ord_wcv decimal(10,2) default 0,
    ord_xlys int default 0,
    ord_xlwc int default 0,
    ord_xlwcv decimal(10,2) default 0,
    ord_dm decimal(10,2) default 0,
    ord_zdmsrwcv decimal(10,2) default 0,
    ord_gjv decimal(10,2) default 0,
    ord_pjpb decimal(10,2) default 0,
    ord_pjmsrwcv decimal(10,2) default 0
)

insert into #temp1(ord_branch,ord_area,ord_store,ord_employee,
                   ord_ysl,ord_wcl ,ord_wcv ,
                   ord_xlys ,ord_xlwc ,ord_xlwcv,ord_dm ,ord_zdmsrwcv,
                   ord_gjv ,ord_pjpb ,ord_pjmsrwcv )
    select [分公司名称],[区域],[门店号],[工号]+[营业员]
      ,[总毛收入预算量],[总毛收入完成量],[总毛收入完成率]*100
      ,[终端预算量],[终端完成量],[终端销量完成率]*100,[终端单毛],[终端毛收入完成率]*100
      ,[增值产品跟机率]*100,[配件配比],[配件毛收入完成率]*100
    from [DBTC].[datas].[dbo].[dd_date] 
    where [数据日期] = @qrydate and [分公司名称] = @qry_branch
      and [区域] is not null and [门店号] = @qry_store and [工号] is not null


select 'tb_report1' tableid ,* from #temp1


END