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

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

end

select count(*) as dataCount from 
order_245
where ord_status != '已作废' and charindex('临',ord_no) = 0
and (@qry_branch = '' or ord_branch = @qry_branch)
and (@qry_creator = '' or ord_creator = @qry_creator )
and (ord_date >= @qry_date1 + ' 00:00:00' and ord_date <= @qry_date2 + ' 23:59:59')

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

END