IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[dbo].[report_25_data]') AND type = 'P')
DROP PROCEDURE [dbo].[report_25_data]
GO
CREATE PROCEDURE report_25_data
@cmpid int,@branchid int,@userdpid int,@userotid int,@useruid int,@tableid varchar(8000),@objids varchar(8000),@pagesize int,@sh_fgs varchar(512)
,@sh_mdmc varchar(512)
,@sh_ygxm varchar(512)
,@sh_rblx varchar(512)
,@sh_kssj varchar(512)
,@sh_jssj 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_256 where ord_status != '已作废' and charindex('临',ord_no) = 0
and (@sh_fgs ='' or ord_branch = @sh_fgs)
and (@sh_mdmc ='' or ord_createdepart = @sh_mdmc)
and (@sh_ygxm ='' or ord_creator = @sh_ygxm)
and (@sh_rblx ='' or ord_rblx = @sh_rblx)
and (ord_date >= @sh_kssj + ' 00:00:00' and ord_date <= @sh_jssj + ' 23:59:59')

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

end


select count(*) as dataCount from 
order_256 where ord_status != '已作废' and charindex('临',ord_no) = 0
and (@sh_fgs ='' or ord_branch = @sh_fgs)
and (@sh_mdmc ='' or ord_createdepart = @sh_mdmc)
and (@sh_ygxm ='' or ord_creator = @sh_ygxm)
and (@sh_rblx ='' or ord_rblx = @sh_rblx)
and (ord_date >= @sh_kssj + ' 00:00:00' and ord_date <= @sh_jssj + ' 23:59:59')

select top 99990 ord_id as dataIds from 
order_256 where ord_status != '已作废' and charindex('临',ord_no) = 0
and (@sh_fgs ='' or ord_branch = @sh_fgs)
and (@sh_mdmc ='' or ord_createdepart = @sh_mdmc)
and (@sh_ygxm ='' or ord_creator = @sh_ygxm)
and (@sh_rblx ='' or ord_rblx = @sh_rblx)
and (ord_date >= @sh_kssj + ' 00:00:00' and ord_date <= @sh_jssj + ' 23:59:59')
 order by ord_id
select top 10 'tb_report1' tableid ,* from 
order_256 where ord_status != '已作废' and charindex('临',ord_no) = 0
and (@sh_fgs ='' or ord_branch = @sh_fgs)
and (@sh_mdmc ='' or ord_createdepart = @sh_mdmc)
and (@sh_ygxm ='' or ord_creator = @sh_ygxm)
and (@sh_rblx ='' or ord_rblx = @sh_rblx)
and (ord_date >= @sh_kssj + ' 00:00:00' and ord_date <= @sh_jssj + ' 23:59:59')
 order by ord_id

END