IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[dbo].[report_26_data]') AND type = 'P')
DROP PROCEDURE [dbo].[report_26_data]
GO
CREATE PROCEDURE report_26_data
@cmpid int,@branchid int,@userdpid int,@userotid int,@useruid int,@tableid varchar(8000),@objids varchar(8000),@pagesize int,@jc_jcgs varchar(512)
,@jc_jcmd varchar(512)
,@jc_jcmddz varchar(512)
,@jc_zgzt varchar(512)
,@jc_jcqk varchar(512)
,@jc_ksrq varchar(512)
,@jc_jsrq 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 ord_no,
ord_date,
ord_creator,
ord_szfgs ,
ord_dpmc ,
ord_mddz,
ord_zgzt ,
ord_bhggs ,
ord2_lrbz ,
ord2_jcqk ,
ord2_wtms,
ord2_sfcl,
ord2_jgsm from 
order_248,order_248_2 where ord_status != '已作废' and charindex('临',ord_no) = 0
and (@jc_jcgs ='' or ord_szfgs = @jc_jcgs)
and (@jc_jcmd ='' or ord_dpmc = @jc_jcmd)
and (@jc_jcmddz ='' or ord_mddz = @jc_jcmddz)
and (@jc_zgzt ='' or ord_zgzt = @jc_zgzt)
and (@jc_jcqk ='' or ord2_jcqk = @jc_jcqk)
and (ord_date >= @jc_ksrq + ' 00:00:00' and ord_date <= @jc_jsrq + ' 23:59:59')
and ord_id = ord2_ordid

       return
    end
    if @objids!='_none_'
    begin
       select ord_no,
ord_date,
ord_creator,
ord_szfgs ,
ord_dpmc ,
ord_mddz,
ord_zgzt ,
ord_bhggs ,
ord2_lrbz ,
ord2_jcqk ,
ord2_wtms,
ord2_sfcl,
ord2_jgsm from @dataIds,order_248,order_248_2 where objid=ord_id 
       return
    end

end


select count(*) as dataCount from 
order_248,order_248_2 where ord_status != '已作废' and charindex('临',ord_no) = 0
and (@jc_jcgs ='' or ord_szfgs = @jc_jcgs)
and (@jc_jcmd ='' or ord_dpmc = @jc_jcmd)
and (@jc_jcmddz ='' or ord_mddz = @jc_jcmddz)
and (@jc_zgzt ='' or ord_zgzt = @jc_zgzt)
and (@jc_jcqk ='' or ord2_jcqk = @jc_jcqk)
and (ord_date >= @jc_ksrq + ' 00:00:00' and ord_date <= @jc_jsrq + ' 23:59:59')
and ord_id = ord2_ordid

select top 99990 ord_id as dataIds from 
order_248,order_248_2 where ord_status != '已作废' and charindex('临',ord_no) = 0
and (@jc_jcgs ='' or ord_szfgs = @jc_jcgs)
and (@jc_jcmd ='' or ord_dpmc = @jc_jcmd)
and (@jc_jcmddz ='' or ord_mddz = @jc_jcmddz)
and (@jc_zgzt ='' or ord_zgzt = @jc_zgzt)
and (@jc_jcqk ='' or ord2_jcqk = @jc_jcqk)
and (ord_date >= @jc_ksrq + ' 00:00:00' and ord_date <= @jc_jsrq + ' 23:59:59')
and ord_id = ord2_ordid
 order by ord_id
select top 10 'tb_report1' tableid ,ord_no,
ord_date,
ord_creator,
ord_szfgs ,
ord_dpmc ,
ord_mddz,
ord_zgzt ,
ord_bhggs ,
ord2_lrbz ,
ord2_jcqk ,
ord2_wtms,
ord2_sfcl,
ord2_jgsm from 
order_248,order_248_2 where ord_status != '已作废' and charindex('临',ord_no) = 0
and (@jc_jcgs ='' or ord_szfgs = @jc_jcgs)
and (@jc_jcmd ='' or ord_dpmc = @jc_jcmd)
and (@jc_jcmddz ='' or ord_mddz = @jc_jcmddz)
and (@jc_zgzt ='' or ord_zgzt = @jc_zgzt)
and (@jc_jcqk ='' or ord2_jcqk = @jc_jcqk)
and (ord_date >= @jc_ksrq + ' 00:00:00' and ord_date <= @jc_jsrq + ' 23:59:59')
and ord_id = ord2_ordid
 order by ord_id

END