IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[dbo].[order_99_query]') AND type = 'P')
DROP PROCEDURE [dbo].[order_99_query]
GO
CREATE  procedure order_99_query(
@cmpid int,@branchid int,@userdpid int,@userotid int ,@useruid int ,@bizid int ,@finished int ,@status nvarchar(50),@pagesize int , @pagecount int , @pageobjids varchar(8000),@ord_pqid_min int,@ord_pqid_max int,@ord_dpbh_min varchar(100), @ord_dpbh_max varchar(100),@ord_cwzh_min varchar(100), @ord_cwzh_max varchar(100),@ord_jdzt_min varchar(100), @ord_jdzt_max varchar(100),@ord_jdfkjg_min varchar(100), @ord_jdfkjg_max varchar(100),@ord_kysj_min datetime,@ord_kysj_max datetime,@ord_htbh_min varchar(100), @ord_htbh_max varchar(100),@ord_ykysj_min datetime,@ord_ykysj_max datetime,@ord_no_min varchar(50), @ord_no_max varchar(50),@ord_creator_min nvarchar(50), @ord_creator_max nvarchar(50),@ord_dpdz_min varchar(100), @ord_dpdz_max varchar(100),@ord_dpmc_min varchar(100), @ord_dpmc_max varchar(100),@ord_dplx_min varchar(100), @ord_dplx_max varchar(100),@ord_dpmj_min int,@ord_dpmj_max int) as begin  
set nocount on  

declare @nonedate datetime 
set @nonedate = CONVERT(datetime,'1910-1-1') 
declare @s1 varchar(8000) 
declare @s2 varchar(100) 
declare @i int 
declare @amount int 
select @amount = @pagecount*@pagesize 
declare @pobjs table(nid int identity(1, 1), ordid bigint) 
set @s1 = @pageobjids 
while (@s1>'') 
begin 
set @i = charindex(',', @s1) 
if (@i>0) 
begin 
set @s2 = substring(@s1,1,@i-1) 
set @s1 = substring(@s1,@i+1,len(@s1)-@i) 
end else  
begin 
set @s2 = @s1 
set @s1 = '' 
end 
insert into @pobjs(ordid) values(convert(bigint,@s2)) 
end 
if (exists (select top 1 * from @pobjs)) 
begin 
select a.* from order_99 a, @pobjs
where ord_id=ordid
order by nid 
select a.* from order_99_users a , @pobjs 
where ordp_ordid=ordid and ordp_cuid=@useruid
return 
end 
if (@status is null or @status = '_none_') set @status = '' 


if (@ord_pqid_min is null or @ord_pqid_min = -999999999) set @ord_pqid_min = -999999999 
if (@ord_pqid_max is null or @ord_pqid_max = -999999999) set @ord_pqid_max = 999999999

if (@ord_dpbh_min is null or @ord_dpbh_min = '_none_') set @ord_dpbh_min = '' 
if (@ord_dpbh_max is null or @ord_dpbh_max = '_none_') set @ord_dpbh_max = '' 

if (@ord_cwzh_min is null or @ord_cwzh_min = '_none_') set @ord_cwzh_min = '' 
if (@ord_cwzh_max is null or @ord_cwzh_max = '_none_') set @ord_cwzh_max = '' 

if (@ord_jdzt_min is null or @ord_jdzt_min = '_none_') set @ord_jdzt_min = '' 
if (@ord_jdzt_max is null or @ord_jdzt_max = '_none_') set @ord_jdzt_max = '' 

if (@ord_jdfkjg_min is null or @ord_jdfkjg_min = '_none_') set @ord_jdfkjg_min = '' 
if (@ord_jdfkjg_max is null or @ord_jdfkjg_max = '_none_') set @ord_jdfkjg_max = '' 


                if (@ord_kysj_min is null or @ord_kysj_min <= @nonedate) set @ord_kysj_min = '1900-01-01' 
                
if (@ord_kysj_max is null or @ord_kysj_max <= @nonedate) set @ord_kysj_max =  '2299-12-30 23:59:59'
else set @ord_kysj_max = @ord_kysj_max+ '23:59:59'
                

if (@ord_htbh_min is null or @ord_htbh_min = '_none_') set @ord_htbh_min = '' 
if (@ord_htbh_max is null or @ord_htbh_max = '_none_') set @ord_htbh_max = '' 


                if (@ord_ykysj_min is null or @ord_ykysj_min <= @nonedate) set @ord_ykysj_min = '1900-01-01' 
                
if (@ord_ykysj_max is null or @ord_ykysj_max <= @nonedate) set @ord_ykysj_max =  '2299-12-30 23:59:59'
else set @ord_ykysj_max = @ord_ykysj_max+ '23:59:59'
                

if (@ord_no_min is null or @ord_no_min = '_none_') set @ord_no_min = '' 
if (@ord_no_max is null or @ord_no_max = '_none_') set @ord_no_max = '' 

if (@ord_creator_min is null or @ord_creator_min = '_none_') set @ord_creator_min = '' 
if (@ord_creator_max is null or @ord_creator_max = '_none_') set @ord_creator_max = '' 

if (@ord_dpdz_min is null or @ord_dpdz_min = '_none_') set @ord_dpdz_min = '' 
if (@ord_dpdz_max is null or @ord_dpdz_max = '_none_') set @ord_dpdz_max = '' 

if (@ord_dpmc_min is null or @ord_dpmc_min = '_none_') set @ord_dpmc_min = '' 
if (@ord_dpmc_max is null or @ord_dpmc_max = '_none_') set @ord_dpmc_max = '' 

if (@ord_dplx_min is null or @ord_dplx_min = '_none_') set @ord_dplx_min = '' 
if (@ord_dplx_max is null or @ord_dplx_max = '_none_') set @ord_dplx_max = '' 

if (@ord_dpmj_min is null or @ord_dpmj_min = -999999999) set @ord_dpmj_min = -999999999 
if (@ord_dpmj_max is null or @ord_dpmj_max = -999999999) set @ord_dpmj_max = 999999999

if @ord_dpbh_min>'' 
begin 
if (charindex('%',@ord_dpbh_min) = 0 and @ord_dpbh_min!='_empty_') 
 begin
set @ord_dpbh_min = '%'+@ord_dpbh_min+'%';
 end else if (@ord_dpbh_min='_empty_') set @ord_dpbh_min='' 
end else
begin 
set @ord_dpbh_min = '%' 
end
if @ord_dpbh_max>'' 
begin 
if (charindex('%', @ord_dpbh_max) = 0 and @ord_dpbh_max!='_empty_') 
begin
set@ord_dpbh_max = '%'+@ord_dpbh_max+'%';
 end else if (@ord_dpbh_max='_empty_') set @ord_dpbh_max='' 
end else
begin 
set @ord_dpbh_max = '%' 
end

if @ord_cwzh_min>'' 
begin 
if (charindex('%',@ord_cwzh_min) = 0 and @ord_cwzh_min!='_empty_') 
 begin
set @ord_cwzh_min = '%'+@ord_cwzh_min+'%';
 end else if (@ord_cwzh_min='_empty_') set @ord_cwzh_min='' 
end else
begin 
set @ord_cwzh_min = '%' 
end
if @ord_cwzh_max>'' 
begin 
if (charindex('%', @ord_cwzh_max) = 0 and @ord_cwzh_max!='_empty_') 
begin
set@ord_cwzh_max = '%'+@ord_cwzh_max+'%';
 end else if (@ord_cwzh_max='_empty_') set @ord_cwzh_max='' 
end else
begin 
set @ord_cwzh_max = '%' 
end

if @ord_jdzt_min>'' 
begin 
if (charindex('%',@ord_jdzt_min) = 0 and @ord_jdzt_min!='_empty_') 
 begin
set @ord_jdzt_min = '%'+@ord_jdzt_min+'%';
 end else if (@ord_jdzt_min='_empty_') set @ord_jdzt_min='' 
end else
begin 
set @ord_jdzt_min = '%' 
end
if @ord_jdzt_max>'' 
begin 
if (charindex('%', @ord_jdzt_max) = 0 and @ord_jdzt_max!='_empty_') 
begin
set@ord_jdzt_max = '%'+@ord_jdzt_max+'%';
 end else if (@ord_jdzt_max='_empty_') set @ord_jdzt_max='' 
end else
begin 
set @ord_jdzt_max = '%' 
end

if @ord_jdfkjg_min>'' 
begin 
if (charindex('%',@ord_jdfkjg_min) = 0 and @ord_jdfkjg_min!='_empty_') 
 begin
set @ord_jdfkjg_min = '%'+@ord_jdfkjg_min+'%';
 end else if (@ord_jdfkjg_min='_empty_') set @ord_jdfkjg_min='' 
end else
begin 
set @ord_jdfkjg_min = '%' 
end
if @ord_jdfkjg_max>'' 
begin 
if (charindex('%', @ord_jdfkjg_max) = 0 and @ord_jdfkjg_max!='_empty_') 
begin
set@ord_jdfkjg_max = '%'+@ord_jdfkjg_max+'%';
 end else if (@ord_jdfkjg_max='_empty_') set @ord_jdfkjg_max='' 
end else
begin 
set @ord_jdfkjg_max = '%' 
end

if @ord_htbh_min>'' 
begin 
if (charindex('%',@ord_htbh_min) = 0 and @ord_htbh_min!='_empty_') 
 begin
set @ord_htbh_min = '%'+@ord_htbh_min+'%';
 end else if (@ord_htbh_min='_empty_') set @ord_htbh_min='' 
end else
begin 
set @ord_htbh_min = '%' 
end
if @ord_htbh_max>'' 
begin 
if (charindex('%', @ord_htbh_max) = 0 and @ord_htbh_max!='_empty_') 
begin
set@ord_htbh_max = '%'+@ord_htbh_max+'%';
 end else if (@ord_htbh_max='_empty_') set @ord_htbh_max='' 
end else
begin 
set @ord_htbh_max = '%' 
end

if @ord_no_min>'' 
begin 
if (charindex('%',@ord_no_min) = 0 and @ord_no_min!='_empty_') 
 begin
set @ord_no_min = '%'+@ord_no_min+'%';
 end else if (@ord_no_min='_empty_') set @ord_no_min='' 
end else
begin 
set @ord_no_min = '%' 
end
if @ord_no_max>'' 
begin 
if (charindex('%', @ord_no_max) = 0 and @ord_no_max!='_empty_') 
begin
set@ord_no_max = '%'+@ord_no_max+'%';
 end else if (@ord_no_max='_empty_') set @ord_no_max='' 
end else
begin 
set @ord_no_max = '%' 
end

if @ord_creator_min>'' 
begin 
if (charindex('%',@ord_creator_min) = 0 and @ord_creator_min!='_empty_') 
 begin
set @ord_creator_min = '%'+@ord_creator_min+'%';
 end else if (@ord_creator_min='_empty_') set @ord_creator_min='' 
end else
begin 
set @ord_creator_min = '%' 
end
if @ord_creator_max>'' 
begin 
if (charindex('%', @ord_creator_max) = 0 and @ord_creator_max!='_empty_') 
begin
set@ord_creator_max = '%'+@ord_creator_max+'%';
 end else if (@ord_creator_max='_empty_') set @ord_creator_max='' 
end else
begin 
set @ord_creator_max = '%' 
end

if @ord_dpdz_min>'' 
begin 
if (charindex('%',@ord_dpdz_min) = 0 and @ord_dpdz_min!='_empty_') 
 begin
set @ord_dpdz_min = '%'+@ord_dpdz_min+'%';
 end else if (@ord_dpdz_min='_empty_') set @ord_dpdz_min='' 
end else
begin 
set @ord_dpdz_min = '%' 
end
if @ord_dpdz_max>'' 
begin 
if (charindex('%', @ord_dpdz_max) = 0 and @ord_dpdz_max!='_empty_') 
begin
set@ord_dpdz_max = '%'+@ord_dpdz_max+'%';
 end else if (@ord_dpdz_max='_empty_') set @ord_dpdz_max='' 
end else
begin 
set @ord_dpdz_max = '%' 
end

if @ord_dpmc_min>'' 
begin 
if (charindex('%',@ord_dpmc_min) = 0 and @ord_dpmc_min!='_empty_') 
 begin
set @ord_dpmc_min = '%'+@ord_dpmc_min+'%';
 end else if (@ord_dpmc_min='_empty_') set @ord_dpmc_min='' 
end else
begin 
set @ord_dpmc_min = '%' 
end
if @ord_dpmc_max>'' 
begin 
if (charindex('%', @ord_dpmc_max) = 0 and @ord_dpmc_max!='_empty_') 
begin
set@ord_dpmc_max = '%'+@ord_dpmc_max+'%';
 end else if (@ord_dpmc_max='_empty_') set @ord_dpmc_max='' 
end else
begin 
set @ord_dpmc_max = '%' 
end

if @ord_dplx_min>'' 
begin 
if (charindex('%',@ord_dplx_min) = 0 and @ord_dplx_min!='_empty_') 
 begin
set @ord_dplx_min = '%'+@ord_dplx_min+'%';
 end else if (@ord_dplx_min='_empty_') set @ord_dplx_min='' 
end else
begin 
set @ord_dplx_min = '%' 
end
if @ord_dplx_max>'' 
begin 
if (charindex('%', @ord_dplx_max) = 0 and @ord_dplx_max!='_empty_') 
begin
set@ord_dplx_max = '%'+@ord_dplx_max+'%';
 end else if (@ord_dplx_max='_empty_') set @ord_dplx_max='' 
end else
begin 
set @ord_dplx_max = '%' 
end
 
    
if (@finished = -11)
begin
if (@pagesize=10000)  -- 下载
begin
select a.* from order_99 a,order_99_users 
where a.ord_cmpid=@cmpid 
and ordp_ordid=a.ord_id 
and ordp_type='bizview' 
and ordp_cuid=@useruid 
and (a.ord_status=@status or @status='') 
and a.ord_finished > 0 
and ord_pqid>=@ord_pqid_min 
and ord_pqid<=@ord_pqid_max 
and ord_dpbh like @ord_dpbh_min 
and ord_dpbh like @ord_dpbh_max 
and ord_cwzh like @ord_cwzh_min 
and ord_cwzh like @ord_cwzh_max 
and ord_jdzt like @ord_jdzt_min 
and ord_jdzt like @ord_jdzt_max 
and ord_jdfkjg like @ord_jdfkjg_min 
and ord_jdfkjg like @ord_jdfkjg_max 
and ord_kysj>=@ord_kysj_min 
and ord_kysj<=@ord_kysj_max 
and ord_htbh like @ord_htbh_min 
and ord_htbh like @ord_htbh_max 
and ord_ykysj>=@ord_ykysj_min 
and ord_ykysj<=@ord_ykysj_max 
and ord_no like @ord_no_min 
and ord_no like @ord_no_max 
and ord_creator like @ord_creator_min 
and ord_creator like @ord_creator_max 
and ord_dpdz like @ord_dpdz_min 
and ord_dpdz like @ord_dpdz_max 
and ord_dpmc like @ord_dpmc_min 
and ord_dpmc like @ord_dpmc_max 
and ord_dplx like @ord_dplx_min 
and ord_dplx like @ord_dplx_max 
and ord_dpmj>=@ord_dpmj_min 
and ord_dpmj<=@ord_dpmj_max 
order by ord_date desc,ord_pqid,ord_dpbh,ord_cwzh,ord_jdzt,ord_jdfkjg,ord_kysj desc,ord_htbh,ord_ykysj desc,ord_no,ord_creator,ord_dpdz,ord_dpmc,ord_dplx,ord_dpmj
end else 
if (@pagesize>=100000000)  --  转存到中间表
begin
set @pagesize = @pagesize - 100000000 
if (@pagesize<=0) set @pagesize = 100000000 
delete datalinker where useruid = @useruid 
insert into datalinker(useruid,objid) 
select top(@pagesize) @useruid,a.ord_id  from order_99 a,order_99_users 
where a.ord_id=ordp_ordid 
and ordp_type='bizview' 
and ordp_cuid=@useruid 
and a.ord_finished > 0
and (a.ord_status=@status or @status='') 
and ord_pqid>=@ord_pqid_min 
and ord_pqid<=@ord_pqid_max 
and ord_dpbh like @ord_dpbh_min 
and ord_dpbh like @ord_dpbh_max 
and ord_cwzh like @ord_cwzh_min 
and ord_cwzh like @ord_cwzh_max 
and ord_jdzt like @ord_jdzt_min 
and ord_jdzt like @ord_jdzt_max 
and ord_jdfkjg like @ord_jdfkjg_min 
and ord_jdfkjg like @ord_jdfkjg_max 
and ord_kysj>=@ord_kysj_min 
and ord_kysj<=@ord_kysj_max 
and ord_htbh like @ord_htbh_min 
and ord_htbh like @ord_htbh_max 
and ord_ykysj>=@ord_ykysj_min 
and ord_ykysj<=@ord_ykysj_max 
and ord_no like @ord_no_min 
and ord_no like @ord_no_max 
and ord_creator like @ord_creator_min 
and ord_creator like @ord_creator_max 
and ord_dpdz like @ord_dpdz_min 
and ord_dpdz like @ord_dpdz_max 
and ord_dpmc like @ord_dpmc_min 
and ord_dpmc like @ord_dpmc_max 
and ord_dplx like @ord_dplx_min 
and ord_dplx like @ord_dplx_max 
and ord_dpmj>=@ord_dpmj_min 
and ord_dpmj<=@ord_dpmj_max 
order by ord_date desc,ord_pqid,ord_dpbh,ord_cwzh,ord_jdzt,ord_jdfkjg,ord_kysj desc,ord_htbh,ord_ykysj desc,ord_no,ord_creator,ord_dpdz,ord_dpmc,ord_dplx,ord_dpmj
select count(1) resultcount  from datalinker where useruid=@useruid 
end else
begin
select count(1) cnt from order_99 a,order_99_users 
where a.ord_id=ordp_ordid 
and a.ord_finished > 0
and ordp_type='bizview' 
and ordp_cuid=@useruid 
and (a.ord_status=@status or @status='') 
and ord_pqid>=@ord_pqid_min 
and ord_pqid<=@ord_pqid_max 
and ord_dpbh like @ord_dpbh_min 
and ord_dpbh like @ord_dpbh_max 
and ord_cwzh like @ord_cwzh_min 
and ord_cwzh like @ord_cwzh_max 
and ord_jdzt like @ord_jdzt_min 
and ord_jdzt like @ord_jdzt_max 
and ord_jdfkjg like @ord_jdfkjg_min 
and ord_jdfkjg like @ord_jdfkjg_max 
and ord_kysj>=@ord_kysj_min 
and ord_kysj<=@ord_kysj_max 
and ord_htbh like @ord_htbh_min 
and ord_htbh like @ord_htbh_max 
and ord_ykysj>=@ord_ykysj_min 
and ord_ykysj<=@ord_ykysj_max 
and ord_no like @ord_no_min 
and ord_no like @ord_no_max 
and ord_creator like @ord_creator_min 
and ord_creator like @ord_creator_max 
and ord_dpdz like @ord_dpdz_min 
and ord_dpdz like @ord_dpdz_max 
and ord_dpmc like @ord_dpmc_min 
and ord_dpmc like @ord_dpmc_max 
and ord_dplx like @ord_dplx_min 
and ord_dplx like @ord_dplx_max 
and ord_dpmj>=@ord_dpmj_min 
and ord_dpmj<=@ord_dpmj_max 

-- 返回所有ID
insert into @pobjs(ordid) select top(@amount) ord_id from order_99 a,order_99_users 
where a.ord_id=ordp_ordid 
and a.ord_finished > 0
and ordp_type='bizview' 
and ordp_cuid=@useruid 
and (a.ord_status=@status or @status='') 
and ord_pqid>=@ord_pqid_min 
and ord_pqid<=@ord_pqid_max 
and ord_dpbh like @ord_dpbh_min 
and ord_dpbh like @ord_dpbh_max 
and ord_cwzh like @ord_cwzh_min 
and ord_cwzh like @ord_cwzh_max 
and ord_jdzt like @ord_jdzt_min 
and ord_jdzt like @ord_jdzt_max 
and ord_jdfkjg like @ord_jdfkjg_min 
and ord_jdfkjg like @ord_jdfkjg_max 
and ord_kysj>=@ord_kysj_min 
and ord_kysj<=@ord_kysj_max 
and ord_htbh like @ord_htbh_min 
and ord_htbh like @ord_htbh_max 
and ord_ykysj>=@ord_ykysj_min 
and ord_ykysj<=@ord_ykysj_max 
and ord_no like @ord_no_min 
and ord_no like @ord_no_max 
and ord_creator like @ord_creator_min 
and ord_creator like @ord_creator_max 
and ord_dpdz like @ord_dpdz_min 
and ord_dpdz like @ord_dpdz_max 
and ord_dpmc like @ord_dpmc_min 
and ord_dpmc like @ord_dpmc_max 
and ord_dplx like @ord_dplx_min 
and ord_dplx like @ord_dplx_max 
and ord_dpmj>=@ord_dpmj_min 
and ord_dpmj<=@ord_dpmj_max 
order by ord_date desc,ord_pqid,ord_dpbh,ord_cwzh,ord_jdzt,ord_jdfkjg,ord_kysj desc,ord_htbh,ord_ykysj desc,ord_no,ord_creator,ord_dpdz,ord_dpmc,ord_dplx,ord_dpmj
select ordid from @pobjs 
order by nid 
-- 返回第一页 
select top(@pagesize) a.* from order_99 a,@pobjs 
where a.ord_id=ordid 
and (a.ord_status=@status or @status='')
and a.ord_finished > 0
order by nid 
-- 返回权限 
select a.* from order_99_users a , @pobjs 
where ordp_ordid=ordid 
and nid<=@pagesize 
and ordp_cuid=@useruid 
end 
end else
if (@finished = -10)
begin
if (@pagesize=10000)  -- 下载
begin
select a.* from order_99 a,order_99_users 
where a.ord_cmpid=@cmpid 
and ordp_type='bizview' 
and ordp_ordid=a.ord_id 
and ordp_cuid=@useruid 
and (a.ord_status=@status or @status='') 
and (a.ord_finished>0 and a.ord_createcuid=@useruid) 
and ord_pqid>=@ord_pqid_min 
and ord_pqid<=@ord_pqid_max 
and ord_dpbh like @ord_dpbh_min 
and ord_dpbh like @ord_dpbh_max 
and ord_cwzh like @ord_cwzh_min 
and ord_cwzh like @ord_cwzh_max 
and ord_jdzt like @ord_jdzt_min 
and ord_jdzt like @ord_jdzt_max 
and ord_jdfkjg like @ord_jdfkjg_min 
and ord_jdfkjg like @ord_jdfkjg_max 
and ord_kysj>=@ord_kysj_min 
and ord_kysj<=@ord_kysj_max 
and ord_htbh like @ord_htbh_min 
and ord_htbh like @ord_htbh_max 
and ord_ykysj>=@ord_ykysj_min 
and ord_ykysj<=@ord_ykysj_max 
and ord_no like @ord_no_min 
and ord_no like @ord_no_max 
and ord_creator like @ord_creator_min 
and ord_creator like @ord_creator_max 
and ord_dpdz like @ord_dpdz_min 
and ord_dpdz like @ord_dpdz_max 
and ord_dpmc like @ord_dpmc_min 
and ord_dpmc like @ord_dpmc_max 
and ord_dplx like @ord_dplx_min 
and ord_dplx like @ord_dplx_max 
and ord_dpmj>=@ord_dpmj_min 
and ord_dpmj<=@ord_dpmj_max 
order by ord_date desc,ord_pqid,ord_dpbh,ord_cwzh,ord_jdzt,ord_jdfkjg,ord_kysj desc,ord_htbh,ord_ykysj desc,ord_no,ord_creator,ord_dpdz,ord_dpmc,ord_dplx,ord_dpmj
end else 
if (@pagesize>=100000000)  --  转存到中间表
begin
set @pagesize = @pagesize - 100000000 
if (@pagesize<=0) set @pagesize = 100000000 
delete datalinker where useruid = @useruid 
insert into datalinker(useruid,objid) 
select top(@pagesize) @useruid,a.ord_id  from order_99 a,order_99_users 
where a.ord_id=ordp_ordid 
and ordp_type='bizview' 
and ordp_cuid=@useruid 
and (a.ord_finished>0 and a.ord_createcuid=@useruid) 
and (a.ord_status=@status or @status='') 
and ord_pqid>=@ord_pqid_min 
and ord_pqid<=@ord_pqid_max 
and ord_dpbh like @ord_dpbh_min 
and ord_dpbh like @ord_dpbh_max 
and ord_cwzh like @ord_cwzh_min 
and ord_cwzh like @ord_cwzh_max 
and ord_jdzt like @ord_jdzt_min 
and ord_jdzt like @ord_jdzt_max 
and ord_jdfkjg like @ord_jdfkjg_min 
and ord_jdfkjg like @ord_jdfkjg_max 
and ord_kysj>=@ord_kysj_min 
and ord_kysj<=@ord_kysj_max 
and ord_htbh like @ord_htbh_min 
and ord_htbh like @ord_htbh_max 
and ord_ykysj>=@ord_ykysj_min 
and ord_ykysj<=@ord_ykysj_max 
and ord_no like @ord_no_min 
and ord_no like @ord_no_max 
and ord_creator like @ord_creator_min 
and ord_creator like @ord_creator_max 
and ord_dpdz like @ord_dpdz_min 
and ord_dpdz like @ord_dpdz_max 
and ord_dpmc like @ord_dpmc_min 
and ord_dpmc like @ord_dpmc_max 
and ord_dplx like @ord_dplx_min 
and ord_dplx like @ord_dplx_max 
and ord_dpmj>=@ord_dpmj_min 
and ord_dpmj<=@ord_dpmj_max 
order by ord_date desc,ord_pqid,ord_dpbh,ord_cwzh,ord_jdzt,ord_jdfkjg,ord_kysj desc,ord_htbh,ord_ykysj desc,ord_no,ord_creator,ord_dpdz,ord_dpmc,ord_dplx,ord_dpmj
select count(1) resultcount  from datalinker where useruid=@useruid 
end else
begin
select count(1) cnt from order_99 a,order_99_users 
where a.ord_id=ordp_ordid 
and (a.ord_finished>0 and a.ord_createcuid=@useruid) 
and ordp_type='bizview' 
and ordp_cuid=@useruid 
and (a.ord_status=@status or @status='') 
and ord_pqid>=@ord_pqid_min 
and ord_pqid<=@ord_pqid_max 
and ord_dpbh like @ord_dpbh_min 
and ord_dpbh like @ord_dpbh_max 
and ord_cwzh like @ord_cwzh_min 
and ord_cwzh like @ord_cwzh_max 
and ord_jdzt like @ord_jdzt_min 
and ord_jdzt like @ord_jdzt_max 
and ord_jdfkjg like @ord_jdfkjg_min 
and ord_jdfkjg like @ord_jdfkjg_max 
and ord_kysj>=@ord_kysj_min 
and ord_kysj<=@ord_kysj_max 
and ord_htbh like @ord_htbh_min 
and ord_htbh like @ord_htbh_max 
and ord_ykysj>=@ord_ykysj_min 
and ord_ykysj<=@ord_ykysj_max 
and ord_no like @ord_no_min 
and ord_no like @ord_no_max 
and ord_creator like @ord_creator_min 
and ord_creator like @ord_creator_max 
and ord_dpdz like @ord_dpdz_min 
and ord_dpdz like @ord_dpdz_max 
and ord_dpmc like @ord_dpmc_min 
and ord_dpmc like @ord_dpmc_max 
and ord_dplx like @ord_dplx_min 
and ord_dplx like @ord_dplx_max 
and ord_dpmj>=@ord_dpmj_min 
and ord_dpmj<=@ord_dpmj_max 

-- 返回所有ID
insert into @pobjs(ordid) select top(@amount) ord_id from order_99 a,order_99_users 
where a.ord_id=ordp_ordid 
and (a.ord_finished>0 and a.ord_createcuid=@useruid) 
and ordp_type='bizview' 
and ordp_cuid=@useruid 
and (a.ord_status=@status or @status='') 
and ord_pqid>=@ord_pqid_min 
and ord_pqid<=@ord_pqid_max 
and ord_dpbh like @ord_dpbh_min 
and ord_dpbh like @ord_dpbh_max 
and ord_cwzh like @ord_cwzh_min 
and ord_cwzh like @ord_cwzh_max 
and ord_jdzt like @ord_jdzt_min 
and ord_jdzt like @ord_jdzt_max 
and ord_jdfkjg like @ord_jdfkjg_min 
and ord_jdfkjg like @ord_jdfkjg_max 
and ord_kysj>=@ord_kysj_min 
and ord_kysj<=@ord_kysj_max 
and ord_htbh like @ord_htbh_min 
and ord_htbh like @ord_htbh_max 
and ord_ykysj>=@ord_ykysj_min 
and ord_ykysj<=@ord_ykysj_max 
and ord_no like @ord_no_min 
and ord_no like @ord_no_max 
and ord_creator like @ord_creator_min 
and ord_creator like @ord_creator_max 
and ord_dpdz like @ord_dpdz_min 
and ord_dpdz like @ord_dpdz_max 
and ord_dpmc like @ord_dpmc_min 
and ord_dpmc like @ord_dpmc_max 
and ord_dplx like @ord_dplx_min 
and ord_dplx like @ord_dplx_max 
and ord_dpmj>=@ord_dpmj_min 
and ord_dpmj<=@ord_dpmj_max 
order by ord_date desc,ord_pqid,ord_dpbh,ord_cwzh,ord_jdzt,ord_jdfkjg,ord_kysj desc,ord_htbh,ord_ykysj desc,ord_no,ord_creator,ord_dpdz,ord_dpmc,ord_dplx,ord_dpmj
select ordid from @pobjs 
order by nid 
-- 返回第一页 
select top(@pagesize) a.* from order_99 a,@pobjs 
where a.ord_id=ordid 
and (a.ord_status=@status or @status='')
and (a.ord_finished>0 and a.ord_createcuid=@useruid) 
order by nid 
-- 返回权限 
select a.* from order_99_users a , @pobjs 
where ordp_ordid=ordid 
and nid<=@pagesize 
and ordp_cuid=@useruid 
end 
end else
if (@finished = 2)
begin
if (@pagesize=10000)  -- 下载
begin
select a.* from order_99 a,order_99_users 
where a.ord_cmpid=@cmpid 
and ordp_ordid=a.ord_id 
and ordp_type='bizview' 
and ordp_cuid=@useruid 
and (a.ord_status=@status or @status='') 
and a.ord_finished>=2 
and ord_pqid>=@ord_pqid_min 
and ord_pqid<=@ord_pqid_max 
and ord_dpbh like @ord_dpbh_min 
and ord_dpbh like @ord_dpbh_max 
and ord_cwzh like @ord_cwzh_min 
and ord_cwzh like @ord_cwzh_max 
and ord_jdzt like @ord_jdzt_min 
and ord_jdzt like @ord_jdzt_max 
and ord_jdfkjg like @ord_jdfkjg_min 
and ord_jdfkjg like @ord_jdfkjg_max 
and ord_kysj>=@ord_kysj_min 
and ord_kysj<=@ord_kysj_max 
and ord_htbh like @ord_htbh_min 
and ord_htbh like @ord_htbh_max 
and ord_ykysj>=@ord_ykysj_min 
and ord_ykysj<=@ord_ykysj_max 
and ord_no like @ord_no_min 
and ord_no like @ord_no_max 
and ord_creator like @ord_creator_min 
and ord_creator like @ord_creator_max 
and ord_dpdz like @ord_dpdz_min 
and ord_dpdz like @ord_dpdz_max 
and ord_dpmc like @ord_dpmc_min 
and ord_dpmc like @ord_dpmc_max 
and ord_dplx like @ord_dplx_min 
and ord_dplx like @ord_dplx_max 
and ord_dpmj>=@ord_dpmj_min 
and ord_dpmj<=@ord_dpmj_max 
order by ord_date desc,ord_pqid,ord_dpbh,ord_cwzh,ord_jdzt,ord_jdfkjg,ord_kysj desc,ord_htbh,ord_ykysj desc,ord_no,ord_creator,ord_dpdz,ord_dpmc,ord_dplx,ord_dpmj
end else 
if (@pagesize>=100000000)  --  转存到中间表
begin
set @pagesize = @pagesize - 100000000 
if (@pagesize<=0) set @pagesize = 100000000 
delete datalinker where useruid = @useruid 
insert into datalinker(useruid,objid) 
select top(@pagesize) @useruid,a.ord_id  from order_99 a,order_99_users 
where a.ord_id=ordp_ordid 
and ordp_type='bizview' 
and ordp_cuid=@useruid 
and a.ord_finished>=2 
and (a.ord_status=@status or @status='') 
and ord_pqid>=@ord_pqid_min 
and ord_pqid<=@ord_pqid_max 
and ord_dpbh like @ord_dpbh_min 
and ord_dpbh like @ord_dpbh_max 
and ord_cwzh like @ord_cwzh_min 
and ord_cwzh like @ord_cwzh_max 
and ord_jdzt like @ord_jdzt_min 
and ord_jdzt like @ord_jdzt_max 
and ord_jdfkjg like @ord_jdfkjg_min 
and ord_jdfkjg like @ord_jdfkjg_max 
and ord_kysj>=@ord_kysj_min 
and ord_kysj<=@ord_kysj_max 
and ord_htbh like @ord_htbh_min 
and ord_htbh like @ord_htbh_max 
and ord_ykysj>=@ord_ykysj_min 
and ord_ykysj<=@ord_ykysj_max 
and ord_no like @ord_no_min 
and ord_no like @ord_no_max 
and ord_creator like @ord_creator_min 
and ord_creator like @ord_creator_max 
and ord_dpdz like @ord_dpdz_min 
and ord_dpdz like @ord_dpdz_max 
and ord_dpmc like @ord_dpmc_min 
and ord_dpmc like @ord_dpmc_max 
and ord_dplx like @ord_dplx_min 
and ord_dplx like @ord_dplx_max 
and ord_dpmj>=@ord_dpmj_min 
and ord_dpmj<=@ord_dpmj_max 
order by ord_date desc,ord_pqid,ord_dpbh,ord_cwzh,ord_jdzt,ord_jdfkjg,ord_kysj desc,ord_htbh,ord_ykysj desc,ord_no,ord_creator,ord_dpdz,ord_dpmc,ord_dplx,ord_dpmj
select count(1) resultcount  from datalinker where useruid=@useruid 
end else
begin
select count(1) cnt from order_99 a,order_99_users 
where a.ord_id=ordp_ordid 
and a.ord_finished>=2 
and ordp_type='bizview' 
and ordp_cuid=@useruid 
and (a.ord_status=@status or @status='') 
and ord_pqid>=@ord_pqid_min 
and ord_pqid<=@ord_pqid_max 
and ord_dpbh like @ord_dpbh_min 
and ord_dpbh like @ord_dpbh_max 
and ord_cwzh like @ord_cwzh_min 
and ord_cwzh like @ord_cwzh_max 
and ord_jdzt like @ord_jdzt_min 
and ord_jdzt like @ord_jdzt_max 
and ord_jdfkjg like @ord_jdfkjg_min 
and ord_jdfkjg like @ord_jdfkjg_max 
and ord_kysj>=@ord_kysj_min 
and ord_kysj<=@ord_kysj_max 
and ord_htbh like @ord_htbh_min 
and ord_htbh like @ord_htbh_max 
and ord_ykysj>=@ord_ykysj_min 
and ord_ykysj<=@ord_ykysj_max 
and ord_no like @ord_no_min 
and ord_no like @ord_no_max 
and ord_creator like @ord_creator_min 
and ord_creator like @ord_creator_max 
and ord_dpdz like @ord_dpdz_min 
and ord_dpdz like @ord_dpdz_max 
and ord_dpmc like @ord_dpmc_min 
and ord_dpmc like @ord_dpmc_max 
and ord_dplx like @ord_dplx_min 
and ord_dplx like @ord_dplx_max 
and ord_dpmj>=@ord_dpmj_min 
and ord_dpmj<=@ord_dpmj_max 

-- 返回所有ID
insert into @pobjs(ordid) select top(@amount) ord_id from order_99 a,order_99_users 
where a.ord_id=ordp_ordid 
and a.ord_finished>=2 
and ordp_type='bizview' 
and ordp_cuid=@useruid 
and (a.ord_status=@status or @status='') 
and ord_pqid>=@ord_pqid_min 
and ord_pqid<=@ord_pqid_max 
and ord_dpbh like @ord_dpbh_min 
and ord_dpbh like @ord_dpbh_max 
and ord_cwzh like @ord_cwzh_min 
and ord_cwzh like @ord_cwzh_max 
and ord_jdzt like @ord_jdzt_min 
and ord_jdzt like @ord_jdzt_max 
and ord_jdfkjg like @ord_jdfkjg_min 
and ord_jdfkjg like @ord_jdfkjg_max 
and ord_kysj>=@ord_kysj_min 
and ord_kysj<=@ord_kysj_max 
and ord_htbh like @ord_htbh_min 
and ord_htbh like @ord_htbh_max 
and ord_ykysj>=@ord_ykysj_min 
and ord_ykysj<=@ord_ykysj_max 
and ord_no like @ord_no_min 
and ord_no like @ord_no_max 
and ord_creator like @ord_creator_min 
and ord_creator like @ord_creator_max 
and ord_dpdz like @ord_dpdz_min 
and ord_dpdz like @ord_dpdz_max 
and ord_dpmc like @ord_dpmc_min 
and ord_dpmc like @ord_dpmc_max 
and ord_dplx like @ord_dplx_min 
and ord_dplx like @ord_dplx_max 
and ord_dpmj>=@ord_dpmj_min 
and ord_dpmj<=@ord_dpmj_max 
order by ord_date desc,ord_pqid,ord_dpbh,ord_cwzh,ord_jdzt,ord_jdfkjg,ord_kysj desc,ord_htbh,ord_ykysj desc,ord_no,ord_creator,ord_dpdz,ord_dpmc,ord_dplx,ord_dpmj
select ordid from @pobjs 
order by nid 
-- 返回第一页 
select top(@pagesize) a.* from order_99 a,@pobjs 
where a.ord_id=ordid 
and (a.ord_status=@status or @status='')
and a.ord_finished>=2 
order by nid 
-- 返回权限 
select a.* from order_99_users a , @pobjs 
where ordp_ordid=ordid 
and nid<=@pagesize 
and ordp_cuid=@useruid 
end 
end else
if (@finished = 1)
begin
if (@pagesize=10000)  -- 下载
begin
select a.* from order_99 a,order_99_users 
where a.ord_cmpid=@cmpid 
and ordp_type='bizview' 
and ordp_cuid=@useruid 
and ordp_ordid=a.ord_id 
and (a.ord_status=@status or @status='') 
and (a.ord_finished>0 and a.ord_finished<=1)
and ord_pqid>=@ord_pqid_min 
and ord_pqid<=@ord_pqid_max 
and ord_dpbh like @ord_dpbh_min 
and ord_dpbh like @ord_dpbh_max 
and ord_cwzh like @ord_cwzh_min 
and ord_cwzh like @ord_cwzh_max 
and ord_jdzt like @ord_jdzt_min 
and ord_jdzt like @ord_jdzt_max 
and ord_jdfkjg like @ord_jdfkjg_min 
and ord_jdfkjg like @ord_jdfkjg_max 
and ord_kysj>=@ord_kysj_min 
and ord_kysj<=@ord_kysj_max 
and ord_htbh like @ord_htbh_min 
and ord_htbh like @ord_htbh_max 
and ord_ykysj>=@ord_ykysj_min 
and ord_ykysj<=@ord_ykysj_max 
and ord_no like @ord_no_min 
and ord_no like @ord_no_max 
and ord_creator like @ord_creator_min 
and ord_creator like @ord_creator_max 
and ord_dpdz like @ord_dpdz_min 
and ord_dpdz like @ord_dpdz_max 
and ord_dpmc like @ord_dpmc_min 
and ord_dpmc like @ord_dpmc_max 
and ord_dplx like @ord_dplx_min 
and ord_dplx like @ord_dplx_max 
and ord_dpmj>=@ord_dpmj_min 
and ord_dpmj<=@ord_dpmj_max 
order by ord_date desc,ord_pqid,ord_dpbh,ord_cwzh,ord_jdzt,ord_jdfkjg,ord_kysj desc,ord_htbh,ord_ykysj desc,ord_no,ord_creator,ord_dpdz,ord_dpmc,ord_dplx,ord_dpmj
end else 
if (@pagesize>=100000000)  --  转存到中间表
begin
set @pagesize = @pagesize - 100000000 
if (@pagesize<=0) set @pagesize = 100000000 
delete datalinker where useruid = @useruid 
insert into datalinker(useruid,objid) 
select top(@pagesize) @useruid,a.ord_id  from order_99 a,order_99_users 
where a.ord_id=ordp_ordid 
and ordp_type='bizview' 
and ordp_cuid=@useruid 
and (a.ord_finished>0 and a.ord_finished<=1)
and (a.ord_status=@status or @status='') 
and ord_pqid>=@ord_pqid_min 
and ord_pqid<=@ord_pqid_max 
and ord_dpbh like @ord_dpbh_min 
and ord_dpbh like @ord_dpbh_max 
and ord_cwzh like @ord_cwzh_min 
and ord_cwzh like @ord_cwzh_max 
and ord_jdzt like @ord_jdzt_min 
and ord_jdzt like @ord_jdzt_max 
and ord_jdfkjg like @ord_jdfkjg_min 
and ord_jdfkjg like @ord_jdfkjg_max 
and ord_kysj>=@ord_kysj_min 
and ord_kysj<=@ord_kysj_max 
and ord_htbh like @ord_htbh_min 
and ord_htbh like @ord_htbh_max 
and ord_ykysj>=@ord_ykysj_min 
and ord_ykysj<=@ord_ykysj_max 
and ord_no like @ord_no_min 
and ord_no like @ord_no_max 
and ord_creator like @ord_creator_min 
and ord_creator like @ord_creator_max 
and ord_dpdz like @ord_dpdz_min 
and ord_dpdz like @ord_dpdz_max 
and ord_dpmc like @ord_dpmc_min 
and ord_dpmc like @ord_dpmc_max 
and ord_dplx like @ord_dplx_min 
and ord_dplx like @ord_dplx_max 
and ord_dpmj>=@ord_dpmj_min 
and ord_dpmj<=@ord_dpmj_max 
order by ord_date desc,ord_pqid,ord_dpbh,ord_cwzh,ord_jdzt,ord_jdfkjg,ord_kysj desc,ord_htbh,ord_ykysj desc,ord_no,ord_creator,ord_dpdz,ord_dpmc,ord_dplx,ord_dpmj
select count(1) resultcount  from datalinker where useruid=@useruid 
end else
begin
select count(1) cnt from order_99 a,order_99_users 
where a.ord_id=ordp_ordid 
and (a.ord_finished>0 and a.ord_finished<=1)
and ordp_type='bizview' 
and ordp_cuid=@useruid 
and (a.ord_status=@status or @status='') 
and ord_pqid>=@ord_pqid_min 
and ord_pqid<=@ord_pqid_max 
and ord_dpbh like @ord_dpbh_min 
and ord_dpbh like @ord_dpbh_max 
and ord_cwzh like @ord_cwzh_min 
and ord_cwzh like @ord_cwzh_max 
and ord_jdzt like @ord_jdzt_min 
and ord_jdzt like @ord_jdzt_max 
and ord_jdfkjg like @ord_jdfkjg_min 
and ord_jdfkjg like @ord_jdfkjg_max 
and ord_kysj>=@ord_kysj_min 
and ord_kysj<=@ord_kysj_max 
and ord_htbh like @ord_htbh_min 
and ord_htbh like @ord_htbh_max 
and ord_ykysj>=@ord_ykysj_min 
and ord_ykysj<=@ord_ykysj_max 
and ord_no like @ord_no_min 
and ord_no like @ord_no_max 
and ord_creator like @ord_creator_min 
and ord_creator like @ord_creator_max 
and ord_dpdz like @ord_dpdz_min 
and ord_dpdz like @ord_dpdz_max 
and ord_dpmc like @ord_dpmc_min 
and ord_dpmc like @ord_dpmc_max 
and ord_dplx like @ord_dplx_min 
and ord_dplx like @ord_dplx_max 
and ord_dpmj>=@ord_dpmj_min 
and ord_dpmj<=@ord_dpmj_max 

-- 返回所有ID
insert into @pobjs(ordid) select top(@amount) ord_id from order_99 a,order_99_users 
where a.ord_id=ordp_ordid 
and (a.ord_finished>0 and a.ord_finished<=1)
and ordp_type='bizview' 
and ordp_cuid=@useruid 
and (a.ord_status=@status or @status='') 
and ord_pqid>=@ord_pqid_min 
and ord_pqid<=@ord_pqid_max 
and ord_dpbh like @ord_dpbh_min 
and ord_dpbh like @ord_dpbh_max 
and ord_cwzh like @ord_cwzh_min 
and ord_cwzh like @ord_cwzh_max 
and ord_jdzt like @ord_jdzt_min 
and ord_jdzt like @ord_jdzt_max 
and ord_jdfkjg like @ord_jdfkjg_min 
and ord_jdfkjg like @ord_jdfkjg_max 
and ord_kysj>=@ord_kysj_min 
and ord_kysj<=@ord_kysj_max 
and ord_htbh like @ord_htbh_min 
and ord_htbh like @ord_htbh_max 
and ord_ykysj>=@ord_ykysj_min 
and ord_ykysj<=@ord_ykysj_max 
and ord_no like @ord_no_min 
and ord_no like @ord_no_max 
and ord_creator like @ord_creator_min 
and ord_creator like @ord_creator_max 
and ord_dpdz like @ord_dpdz_min 
and ord_dpdz like @ord_dpdz_max 
and ord_dpmc like @ord_dpmc_min 
and ord_dpmc like @ord_dpmc_max 
and ord_dplx like @ord_dplx_min 
and ord_dplx like @ord_dplx_max 
and ord_dpmj>=@ord_dpmj_min 
and ord_dpmj<=@ord_dpmj_max 
order by ord_date desc,ord_pqid,ord_dpbh,ord_cwzh,ord_jdzt,ord_jdfkjg,ord_kysj desc,ord_htbh,ord_ykysj desc,ord_no,ord_creator,ord_dpdz,ord_dpmc,ord_dplx,ord_dpmj
select ordid from @pobjs 
order by nid 
-- 返回第一页 
select top(@pagesize) a.* from order_99 a,@pobjs 
where a.ord_id=ordid 
and (a.ord_status=@status or @status='')
and (a.ord_finished>0 and a.ord_finished<=1) 
order by nid 
-- 返回权限 
select a.* from order_99_users a , @pobjs 
where ordp_ordid=ordid 
and nid<=@pagesize 
and ordp_cuid=@useruid 
end 
end else
if (@finished = -1)
begin
if (@pagesize=10000)  -- 下载
begin
select a.* from order_99 a,order_99_users 
where a.ord_cmpid=@cmpid 
and ordp_type='bizview' 
and ordp_ordid=a.ord_id 
and ordp_cuid=@useruid 
and (a.ord_status=@status or @status='') 
and ord_finished=-1 
and ord_pqid>=@ord_pqid_min 
and ord_pqid<=@ord_pqid_max 
and ord_dpbh like @ord_dpbh_min 
and ord_dpbh like @ord_dpbh_max 
and ord_cwzh like @ord_cwzh_min 
and ord_cwzh like @ord_cwzh_max 
and ord_jdzt like @ord_jdzt_min 
and ord_jdzt like @ord_jdzt_max 
and ord_jdfkjg like @ord_jdfkjg_min 
and ord_jdfkjg like @ord_jdfkjg_max 
and ord_kysj>=@ord_kysj_min 
and ord_kysj<=@ord_kysj_max 
and ord_htbh like @ord_htbh_min 
and ord_htbh like @ord_htbh_max 
and ord_ykysj>=@ord_ykysj_min 
and ord_ykysj<=@ord_ykysj_max 
and ord_no like @ord_no_min 
and ord_no like @ord_no_max 
and ord_creator like @ord_creator_min 
and ord_creator like @ord_creator_max 
and ord_dpdz like @ord_dpdz_min 
and ord_dpdz like @ord_dpdz_max 
and ord_dpmc like @ord_dpmc_min 
and ord_dpmc like @ord_dpmc_max 
and ord_dplx like @ord_dplx_min 
and ord_dplx like @ord_dplx_max 
and ord_dpmj>=@ord_dpmj_min 
and ord_dpmj<=@ord_dpmj_max 
order by ord_date desc,ord_pqid,ord_dpbh,ord_cwzh,ord_jdzt,ord_jdfkjg,ord_kysj desc,ord_htbh,ord_ykysj desc,ord_no,ord_creator,ord_dpdz,ord_dpmc,ord_dplx,ord_dpmj
end else 
if (@pagesize>=100000000)  --  转存到中间表
begin
set @pagesize = @pagesize - 100000000 
if (@pagesize<=0) set @pagesize = 100000000 
delete datalinker where useruid = @useruid 
insert into datalinker(useruid,objid) 
select top(@pagesize) @useruid,a.ord_id  from order_99 a,order_99_users 
where a.ord_id=ordp_ordid 
and ordp_type='bizview' 
and ordp_cuid=@useruid 
and ord_finished=-1 
and (a.ord_status=@status or @status='') 
and ord_pqid>=@ord_pqid_min 
and ord_pqid<=@ord_pqid_max 
and ord_dpbh like @ord_dpbh_min 
and ord_dpbh like @ord_dpbh_max 
and ord_cwzh like @ord_cwzh_min 
and ord_cwzh like @ord_cwzh_max 
and ord_jdzt like @ord_jdzt_min 
and ord_jdzt like @ord_jdzt_max 
and ord_jdfkjg like @ord_jdfkjg_min 
and ord_jdfkjg like @ord_jdfkjg_max 
and ord_kysj>=@ord_kysj_min 
and ord_kysj<=@ord_kysj_max 
and ord_htbh like @ord_htbh_min 
and ord_htbh like @ord_htbh_max 
and ord_ykysj>=@ord_ykysj_min 
and ord_ykysj<=@ord_ykysj_max 
and ord_no like @ord_no_min 
and ord_no like @ord_no_max 
and ord_creator like @ord_creator_min 
and ord_creator like @ord_creator_max 
and ord_dpdz like @ord_dpdz_min 
and ord_dpdz like @ord_dpdz_max 
and ord_dpmc like @ord_dpmc_min 
and ord_dpmc like @ord_dpmc_max 
and ord_dplx like @ord_dplx_min 
and ord_dplx like @ord_dplx_max 
and ord_dpmj>=@ord_dpmj_min 
and ord_dpmj<=@ord_dpmj_max 
order by ord_date desc,ord_pqid,ord_dpbh,ord_cwzh,ord_jdzt,ord_jdfkjg,ord_kysj desc,ord_htbh,ord_ykysj desc,ord_no,ord_creator,ord_dpdz,ord_dpmc,ord_dplx,ord_dpmj
select count(1) resultcount  from datalinker where useruid=@useruid 
end else
begin
select count(1) cnt from order_99 a,order_99_users 
where a.ord_id=ordp_ordid 
and ord_finished=-1 
and ordp_type='bizview' 
and ordp_cuid=@useruid 
and (a.ord_status=@status or @status='') 
and ord_pqid>=@ord_pqid_min 
and ord_pqid<=@ord_pqid_max 
and ord_dpbh like @ord_dpbh_min 
and ord_dpbh like @ord_dpbh_max 
and ord_cwzh like @ord_cwzh_min 
and ord_cwzh like @ord_cwzh_max 
and ord_jdzt like @ord_jdzt_min 
and ord_jdzt like @ord_jdzt_max 
and ord_jdfkjg like @ord_jdfkjg_min 
and ord_jdfkjg like @ord_jdfkjg_max 
and ord_kysj>=@ord_kysj_min 
and ord_kysj<=@ord_kysj_max 
and ord_htbh like @ord_htbh_min 
and ord_htbh like @ord_htbh_max 
and ord_ykysj>=@ord_ykysj_min 
and ord_ykysj<=@ord_ykysj_max 
and ord_no like @ord_no_min 
and ord_no like @ord_no_max 
and ord_creator like @ord_creator_min 
and ord_creator like @ord_creator_max 
and ord_dpdz like @ord_dpdz_min 
and ord_dpdz like @ord_dpdz_max 
and ord_dpmc like @ord_dpmc_min 
and ord_dpmc like @ord_dpmc_max 
and ord_dplx like @ord_dplx_min 
and ord_dplx like @ord_dplx_max 
and ord_dpmj>=@ord_dpmj_min 
and ord_dpmj<=@ord_dpmj_max 

-- 返回所有ID
insert into @pobjs(ordid) select top(@amount) ord_id from order_99 a,order_99_users 
where a.ord_id=ordp_ordid 
and ord_finished=-1 
and ordp_type='bizview' 
and ordp_cuid=@useruid 
and (a.ord_status=@status or @status='') 
and ord_pqid>=@ord_pqid_min 
and ord_pqid<=@ord_pqid_max 
and ord_dpbh like @ord_dpbh_min 
and ord_dpbh like @ord_dpbh_max 
and ord_cwzh like @ord_cwzh_min 
and ord_cwzh like @ord_cwzh_max 
and ord_jdzt like @ord_jdzt_min 
and ord_jdzt like @ord_jdzt_max 
and ord_jdfkjg like @ord_jdfkjg_min 
and ord_jdfkjg like @ord_jdfkjg_max 
and ord_kysj>=@ord_kysj_min 
and ord_kysj<=@ord_kysj_max 
and ord_htbh like @ord_htbh_min 
and ord_htbh like @ord_htbh_max 
and ord_ykysj>=@ord_ykysj_min 
and ord_ykysj<=@ord_ykysj_max 
and ord_no like @ord_no_min 
and ord_no like @ord_no_max 
and ord_creator like @ord_creator_min 
and ord_creator like @ord_creator_max 
and ord_dpdz like @ord_dpdz_min 
and ord_dpdz like @ord_dpdz_max 
and ord_dpmc like @ord_dpmc_min 
and ord_dpmc like @ord_dpmc_max 
and ord_dplx like @ord_dplx_min 
and ord_dplx like @ord_dplx_max 
and ord_dpmj>=@ord_dpmj_min 
and ord_dpmj<=@ord_dpmj_max 
order by ord_date desc,ord_pqid,ord_dpbh,ord_cwzh,ord_jdzt,ord_jdfkjg,ord_kysj desc,ord_htbh,ord_ykysj desc,ord_no,ord_creator,ord_dpdz,ord_dpmc,ord_dplx,ord_dpmj
select ordid from @pobjs 
order by nid 
-- 返回第一页 
select top(@pagesize) a.* from order_99 a,@pobjs 
where a.ord_id=ordid 
and (a.ord_status=@status or @status='')
and ord_finished=-1 
order by nid 
-- 返回权限 
select a.* from order_99_users a , @pobjs 
where ordp_ordid=ordid 
and nid<=@pagesize 
and ordp_cuid=@useruid 
end 
end 
set nocount off end