IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[dbo].[report_40_data]') AND type = 'P')
DROP PROCEDURE [dbo].[report_40_data]
GO
CREATE PROCEDURE report_40_data
@cmpid int,@branchid int,@userdpid int,@userotid int,@useruid int,@tableid varchar(8000),@objids varchar(8000),@pagesize int,@qry_fgs varchar(512)
,@qry_ywzt varchar(512)
,@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)

--一个table模板数据集包含以下代码
--以下是我们写报表时的代码，只需将本代码块修改后放入”报表数据(SQL)“中即可
-->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

--@tableid 指要加载数据的table的ID属性值
if @tableid='tb_report1'
begin
  --若是下载，前端自动传入pagesize = 10000
  if @pagesize=10000
  begin

    select ord_id,convert(varchar,ord_date,23) as ord_date,ord_mdbm,ord_createdepart,ord_hhbm,ord_pp,ord_xh
      ,ord_khxm,ord_gz,ord_ywxs,ord_creator,ord_gcs,ord_bz,ord_bmje,convert(varchar,ord_bmsj,23) as ord_bmsj
      ,ord_status,ord_jjzt,convert(varchar,ord_fhsj,23) as ord_fhsj,convert(varchar,ord_shsj,23) as ord_shsj        
    from order_265 
    where ord_status != '已作废' 
    and charindex('临',ord_no) = 0
    and (@qry_fgs = '' or ord_branch = @qry_fgs)
    and (@qry_ywzt = '' or ord_status like '%' + @qry_ywzt + '%')
    and (ord_date >= @qry_date1 + ' 00:00:00' and ord_date <= @qry_date2 + ' 23:59:59')
     return
  end
  --若是分页，
  --1.若是首次加载，则@objids ='_none_'
  --2.若是下一页操作，则前端会自动传入nextpage的ID,如：objids = "ord_id,ord_id,ord_id,ord_id"
  if @objids!='_none_'
  begin
    select ord_id,convert(varchar,ord_date,23) as ord_date,ord_mdbm,ord_createdepart,ord_hhbm,ord_pp,ord_xh
      ,ord_khxm,ord_gz,ord_ywxs,ord_creator,ord_gcs,ord_bz,ord_bmje,convert(varchar,ord_bmsj,23) as ord_bmsj
      ,ord_status,ord_jjzt,convert(varchar,ord_fhsj,23) as ord_fhsj,convert(varchar,ord_shsj,23) as ord_shsj
    from order_265 ,@dataIds 
    where objid=ord_id 
    
     return
  end
end

--若是分页，且首次加载，即@objids ='_none_'，执行以下取数据逻辑
--获取总数

  select  count(*) as dataCount     
    from order_265 
    where ord_status != '已作废' 
    and charindex('临',ord_no) = 0
    and (@qry_fgs = '' or ord_branch = @qry_fgs)
    and (@qry_ywzt = '' or ord_status like '%' + @qry_ywzt + '%')
    and (ord_date >= @qry_date1 + ' 00:00:00' and ord_date <= @qry_date2 + ' 23:59:59')

--获取分页最多显示的数量
select  top 1000 ord_id as dataIds       
    from order_265 
    where ord_status != '已作废' 
    and charindex('临',ord_no) = 0
    and (@qry_fgs = '' or ord_branch = @qry_fgs)
    and (@qry_ywzt = '' or ord_status like '%' + @qry_ywzt + '%')
    and (ord_date >= @qry_date1 + ' 00:00:00' and ord_date <= @qry_date2 + ' 23:59:59')
--获取第一页显示的数量
select  top 10 'tb_report1' tableid ,ord_id,convert(varchar,ord_date,23) as ord_date,ord_mdbm,ord_createdepart,ord_hhbm,ord_pp,ord_xh
      ,ord_khxm,ord_gz,ord_ywxs,ord_creator,ord_gcs,ord_bz,ord_bmje,convert(varchar,ord_bmsj,23) as ord_bmsj
      ,ord_status,ord_jjzt,convert(varchar,ord_fhsj,23) as ord_fhsj,convert(varchar,ord_shsj,23) as ord_shsj
    from order_265 
    where ord_status != '已作废' 
    and charindex('临',ord_no) = 0
    and (@qry_fgs = '' or ord_branch = @qry_fgs)
    and (@qry_ywzt = '' or ord_status like '%' + @qry_ywzt + '%')
    and (ord_date >= @qry_date1 + ' 00:00:00' and ord_date <= @qry_date2 + ' 23:59:59')
--<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
--一个table模板数据集包含以下代码
--<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
END