IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[dbo].[report_23_data]') AND type = 'P')
DROP PROCEDURE [dbo].[report_23_data]
GO
CREATE PROCEDURE report_23_data
@cmpid int,@branchid int,@userdpid int,@userotid int,@useruid int,@tableid varchar(8000),@objids varchar(8000),@pagesize int,@qry_fgs varchar(512)
,@qry_depart varchar(512)
,@qry_creator varchar(512)
,@qry_date1 varchar(512)
,@qry_date2 varchar(512)
,@qry_mdlx 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)
if @tableid='tb_report1'
begin
    if @pagesize=10000
    begin
       select * from 
order_252 where ord_status != '已作废' and charindex('临',ord_no) = 0
and (@qry_fgs = '' or ord_xzfgs = @qry_fgs)
and (@qry_depart = '' or ord_mdmc = @qry_depart)
and (@qry_creator = '' or ord_creator = @qry_creator )
and (ord_date >= @qry_date1 + ' 00:00:00' and ord_date <= @qry_date2 + ' 23:59:59')
and (@qry_mdlx = '' or ord_mdlx = @qry_mdlx)

       return
    end
    if @objids!='_none_'
    begin
       select * from @dataIds,order_252 where objid=ord_id
       return
    end

end


select count(*) as dataCount from 
order_252 where ord_status != '已作废' and charindex('临',ord_no) = 0
and (@qry_fgs = '' or ord_xzfgs = @qry_fgs)
and (@qry_depart = '' or ord_mdmc = @qry_depart)
and (@qry_creator = '' or ord_creator = @qry_creator )
and (ord_date >= @qry_date1 + ' 00:00:00' and ord_date <= @qry_date2 + ' 23:59:59')
and (@qry_mdlx = '' or ord_mdlx = @qry_mdlx)

select top 99990 ord_id as dataIds from 
order_252 where ord_status != '已作废' and charindex('临',ord_no) = 0
and (@qry_fgs = '' or ord_xzfgs = @qry_fgs)
and (@qry_depart = '' or ord_mdmc = @qry_depart)
and (@qry_creator = '' or ord_creator = @qry_creator )
and (ord_date >= @qry_date1 + ' 00:00:00' and ord_date <= @qry_date2 + ' 23:59:59')
and (@qry_mdlx = '' or ord_mdlx = @qry_mdlx)
 order by ord_id
select top 10 'tb_report1' tableid ,* from 
order_252 where ord_status != '已作废' and charindex('临',ord_no) = 0
and (@qry_fgs = '' or ord_xzfgs = @qry_fgs)
and (@qry_depart = '' or ord_mdmc = @qry_depart)
and (@qry_creator = '' or ord_creator = @qry_creator )
and (ord_date >= @qry_date1 + ' 00:00:00' and ord_date <= @qry_date2 + ' 23:59:59')
and (@qry_mdlx = '' or ord_mdlx = @qry_mdlx)
 order by ord_id

END