IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[dbo].[order_175_query]') AND type = 'P')
DROP PROCEDURE [dbo].[order_175_query]
GO
CREATE  procedure order_175_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_creator_min nvarchar(50), @ord_creator_max nvarchar(50),@ord_tkfs_min varchar(100), @ord_tkfs_max varchar(100),@ord_sfzhm_min varchar(100), @ord_sfzhm_max varchar(100),@ord_yxqh_min varchar(100), @ord_yxqh_max varchar(100),@ord_vipqh_min varchar(100), @ord_vipqh_max varchar(100),@ord_tkje_min int,@ord_tkje_max int,@ord_status_min nvarchar(30), @ord_status_max nvarchar(30),@ord_dpmc_min varchar(100), @ord_dpmc_max varchar(100),@ord_createdepart_min nvarchar(50), @ord_createdepart_max nvarchar(50),@ord_date_min datetime,@ord_date_max datetime,@ord_dh_min varchar(100), @ord_dh_max varchar(100),@ord_gmsj_min datetime,@ord_gmsj_max datetime,@ord_hz_min varchar(100), @ord_hz_max varchar(100),@ord_khx_min varchar(100), @ord_khx_max varchar(100),@ord_khxm_min varchar(100), @ord_khxm_max varchar(100),@ord_no_min varchar(50), @ord_no_max varchar(50)) 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_175 a, @pobjs
where ord_id=ordid
order by nid 
select a.* from order_175_users a , @pobjs 
where ordp_ordid=ordid and ordp_cuid=@useruid
return 
end 
if (@status is null or @status = '_none_') set @status = '' 


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_tkfs_min is null or @ord_tkfs_min = '_none_') set @ord_tkfs_min = '' 
if (@ord_tkfs_max is null or @ord_tkfs_max = '_none_') set @ord_tkfs_max = '' 

if (@ord_sfzhm_min is null or @ord_sfzhm_min = '_none_') set @ord_sfzhm_min = '' 
if (@ord_sfzhm_max is null or @ord_sfzhm_max = '_none_') set @ord_sfzhm_max = '' 

if (@ord_yxqh_min is null or @ord_yxqh_min = '_none_') set @ord_yxqh_min = '' 
if (@ord_yxqh_max is null or @ord_yxqh_max = '_none_') set @ord_yxqh_max = '' 

if (@ord_vipqh_min is null or @ord_vipqh_min = '_none_') set @ord_vipqh_min = '' 
if (@ord_vipqh_max is null or @ord_vipqh_max = '_none_') set @ord_vipqh_max = '' 

if (@ord_tkje_min is null or @ord_tkje_min = -999999999) set @ord_tkje_min = -999999999 
if (@ord_tkje_max is null or @ord_tkje_max = -999999999) set @ord_tkje_max = 999999999

if (@ord_status_min is null or @ord_status_min = '_none_') set @ord_status_min = '' 
if (@ord_status_max is null or @ord_status_max = '_none_') set @ord_status_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_createdepart_min is null or @ord_createdepart_min = '_none_') set @ord_createdepart_min = '' 
if (@ord_createdepart_max is null or @ord_createdepart_max = '_none_') set @ord_createdepart_max = '' 


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

if (@ord_dh_min is null or @ord_dh_min = '_none_') set @ord_dh_min = '' 
if (@ord_dh_max is null or @ord_dh_max = '_none_') set @ord_dh_max = '' 


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

if (@ord_hz_min is null or @ord_hz_min = '_none_') set @ord_hz_min = '' 
if (@ord_hz_max is null or @ord_hz_max = '_none_') set @ord_hz_max = '' 

if (@ord_khx_min is null or @ord_khx_min = '_none_') set @ord_khx_min = '' 
if (@ord_khx_max is null or @ord_khx_max = '_none_') set @ord_khx_max = '' 

if (@ord_khxm_min is null or @ord_khxm_min = '_none_') set @ord_khxm_min = '' 
if (@ord_khxm_max is null or @ord_khxm_max = '_none_') set @ord_khxm_max = '' 

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>'' 
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_tkfs_min>'' 
begin 
if (charindex('%',@ord_tkfs_min) = 0 and @ord_tkfs_min!='_empty_') 
 begin
set @ord_tkfs_min = '%'+@ord_tkfs_min+'%';
 end else if (@ord_tkfs_min='_empty_') set @ord_tkfs_min='' 
end else
begin 
set @ord_tkfs_min = '%' 
end
if @ord_tkfs_max>'' 
begin 
if (charindex('%', @ord_tkfs_max) = 0 and @ord_tkfs_max!='_empty_') 
begin
set@ord_tkfs_max = '%'+@ord_tkfs_max+'%';
 end else if (@ord_tkfs_max='_empty_') set @ord_tkfs_max='' 
end else
begin 
set @ord_tkfs_max = '%' 
end

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

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

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

if @ord_status_min>'' 
begin 
if (charindex('%',@ord_status_min) = 0 and @ord_status_min!='_empty_') 
 begin
set @ord_status_min = '%'+@ord_status_min+'%';
 end else if (@ord_status_min='_empty_') set @ord_status_min='' 
end else
begin 
set @ord_status_min = '%' 
end
if @ord_status_max>'' 
begin 
if (charindex('%', @ord_status_max) = 0 and @ord_status_max!='_empty_') 
begin
set@ord_status_max = '%'+@ord_status_max+'%';
 end else if (@ord_status_max='_empty_') set @ord_status_max='' 
end else
begin 
set @ord_status_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_createdepart_min>'' 
begin 
if (charindex('%',@ord_createdepart_min) = 0 and @ord_createdepart_min!='_empty_') 
 begin
set @ord_createdepart_min = '%'+@ord_createdepart_min+'%';
 end else if (@ord_createdepart_min='_empty_') set @ord_createdepart_min='' 
end else
begin 
set @ord_createdepart_min = '%' 
end
if @ord_createdepart_max>'' 
begin 
if (charindex('%', @ord_createdepart_max) = 0 and @ord_createdepart_max!='_empty_') 
begin
set@ord_createdepart_max = '%'+@ord_createdepart_max+'%';
 end else if (@ord_createdepart_max='_empty_') set @ord_createdepart_max='' 
end else
begin 
set @ord_createdepart_max = '%' 
end

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

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

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

if @ord_khxm_min>'' 
begin 
if (charindex('%',@ord_khxm_min) = 0 and @ord_khxm_min!='_empty_') 
 begin
set @ord_khxm_min = '%'+@ord_khxm_min+'%';
 end else if (@ord_khxm_min='_empty_') set @ord_khxm_min='' 
end else
begin 
set @ord_khxm_min = '%' 
end
if @ord_khxm_max>'' 
begin 
if (charindex('%', @ord_khxm_max) = 0 and @ord_khxm_max!='_empty_') 
begin
set@ord_khxm_max = '%'+@ord_khxm_max+'%';
 end else if (@ord_khxm_max='_empty_') set @ord_khxm_max='' 
end else
begin 
set @ord_khxm_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 (@finished = -11)
begin
if (@pagesize=10000)  -- 下载
begin
select a.* from order_175 a,order_175_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_creator like @ord_creator_min 
and ord_creator like @ord_creator_max 
and ord_tkfs like @ord_tkfs_min 
and ord_tkfs like @ord_tkfs_max 
and ord_sfzhm like @ord_sfzhm_min 
and ord_sfzhm like @ord_sfzhm_max 
and ord_yxqh like @ord_yxqh_min 
and ord_yxqh like @ord_yxqh_max 
and ord_vipqh like @ord_vipqh_min 
and ord_vipqh like @ord_vipqh_max 
and ord_tkje>=@ord_tkje_min 
and ord_tkje<=@ord_tkje_max 
and ord_status like @ord_status_min 
and ord_status like @ord_status_max 
and ord_dpmc like @ord_dpmc_min 
and ord_dpmc like @ord_dpmc_max 
and ord_createdepart like @ord_createdepart_min 
and ord_createdepart like @ord_createdepart_max 
and ord_date>=@ord_date_min 
and ord_date<=@ord_date_max 
and ord_dh like @ord_dh_min 
and ord_dh like @ord_dh_max 
and ord_gmsj>=@ord_gmsj_min 
and ord_gmsj<=@ord_gmsj_max 
and ord_hz like @ord_hz_min 
and ord_hz like @ord_hz_max 
and ord_khx like @ord_khx_min 
and ord_khx like @ord_khx_max 
and ord_khxm like @ord_khxm_min 
and ord_khxm like @ord_khxm_max 
and ord_no like @ord_no_min 
and ord_no like @ord_no_max 
order by ord_date desc,ord_creator,ord_tkfs,ord_sfzhm,ord_yxqh,ord_vipqh,ord_tkje,ord_status,ord_dpmc,ord_createdepart,ord_dh,ord_gmsj desc,ord_hz,ord_khx,ord_khxm,ord_no
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_175 a,order_175_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_creator like @ord_creator_min 
and ord_creator like @ord_creator_max 
and ord_tkfs like @ord_tkfs_min 
and ord_tkfs like @ord_tkfs_max 
and ord_sfzhm like @ord_sfzhm_min 
and ord_sfzhm like @ord_sfzhm_max 
and ord_yxqh like @ord_yxqh_min 
and ord_yxqh like @ord_yxqh_max 
and ord_vipqh like @ord_vipqh_min 
and ord_vipqh like @ord_vipqh_max 
and ord_tkje>=@ord_tkje_min 
and ord_tkje<=@ord_tkje_max 
and ord_status like @ord_status_min 
and ord_status like @ord_status_max 
and ord_dpmc like @ord_dpmc_min 
and ord_dpmc like @ord_dpmc_max 
and ord_createdepart like @ord_createdepart_min 
and ord_createdepart like @ord_createdepart_max 
and ord_date>=@ord_date_min 
and ord_date<=@ord_date_max 
and ord_dh like @ord_dh_min 
and ord_dh like @ord_dh_max 
and ord_gmsj>=@ord_gmsj_min 
and ord_gmsj<=@ord_gmsj_max 
and ord_hz like @ord_hz_min 
and ord_hz like @ord_hz_max 
and ord_khx like @ord_khx_min 
and ord_khx like @ord_khx_max 
and ord_khxm like @ord_khxm_min 
and ord_khxm like @ord_khxm_max 
and ord_no like @ord_no_min 
and ord_no like @ord_no_max 
order by ord_date desc,ord_creator,ord_tkfs,ord_sfzhm,ord_yxqh,ord_vipqh,ord_tkje,ord_status,ord_dpmc,ord_createdepart,ord_dh,ord_gmsj desc,ord_hz,ord_khx,ord_khxm,ord_no
select count(1) resultcount  from datalinker where useruid=@useruid 
end else
begin
select count(1) cnt from order_175 a,order_175_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_creator like @ord_creator_min 
and ord_creator like @ord_creator_max 
and ord_tkfs like @ord_tkfs_min 
and ord_tkfs like @ord_tkfs_max 
and ord_sfzhm like @ord_sfzhm_min 
and ord_sfzhm like @ord_sfzhm_max 
and ord_yxqh like @ord_yxqh_min 
and ord_yxqh like @ord_yxqh_max 
and ord_vipqh like @ord_vipqh_min 
and ord_vipqh like @ord_vipqh_max 
and ord_tkje>=@ord_tkje_min 
and ord_tkje<=@ord_tkje_max 
and ord_status like @ord_status_min 
and ord_status like @ord_status_max 
and ord_dpmc like @ord_dpmc_min 
and ord_dpmc like @ord_dpmc_max 
and ord_createdepart like @ord_createdepart_min 
and ord_createdepart like @ord_createdepart_max 
and ord_date>=@ord_date_min 
and ord_date<=@ord_date_max 
and ord_dh like @ord_dh_min 
and ord_dh like @ord_dh_max 
and ord_gmsj>=@ord_gmsj_min 
and ord_gmsj<=@ord_gmsj_max 
and ord_hz like @ord_hz_min 
and ord_hz like @ord_hz_max 
and ord_khx like @ord_khx_min 
and ord_khx like @ord_khx_max 
and ord_khxm like @ord_khxm_min 
and ord_khxm like @ord_khxm_max 
and ord_no like @ord_no_min 
and ord_no like @ord_no_max 

-- 返回所有ID
insert into @pobjs(ordid) select top(@amount) ord_id from order_175 a,order_175_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_creator like @ord_creator_min 
and ord_creator like @ord_creator_max 
and ord_tkfs like @ord_tkfs_min 
and ord_tkfs like @ord_tkfs_max 
and ord_sfzhm like @ord_sfzhm_min 
and ord_sfzhm like @ord_sfzhm_max 
and ord_yxqh like @ord_yxqh_min 
and ord_yxqh like @ord_yxqh_max 
and ord_vipqh like @ord_vipqh_min 
and ord_vipqh like @ord_vipqh_max 
and ord_tkje>=@ord_tkje_min 
and ord_tkje<=@ord_tkje_max 
and ord_status like @ord_status_min 
and ord_status like @ord_status_max 
and ord_dpmc like @ord_dpmc_min 
and ord_dpmc like @ord_dpmc_max 
and ord_createdepart like @ord_createdepart_min 
and ord_createdepart like @ord_createdepart_max 
and ord_date>=@ord_date_min 
and ord_date<=@ord_date_max 
and ord_dh like @ord_dh_min 
and ord_dh like @ord_dh_max 
and ord_gmsj>=@ord_gmsj_min 
and ord_gmsj<=@ord_gmsj_max 
and ord_hz like @ord_hz_min 
and ord_hz like @ord_hz_max 
and ord_khx like @ord_khx_min 
and ord_khx like @ord_khx_max 
and ord_khxm like @ord_khxm_min 
and ord_khxm like @ord_khxm_max 
and ord_no like @ord_no_min 
and ord_no like @ord_no_max 
order by ord_date desc,ord_creator,ord_tkfs,ord_sfzhm,ord_yxqh,ord_vipqh,ord_tkje,ord_status,ord_dpmc,ord_createdepart,ord_dh,ord_gmsj desc,ord_hz,ord_khx,ord_khxm,ord_no
select ordid from @pobjs 
order by nid 
-- 返回第一页 
select top(@pagesize) a.* from order_175 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_175_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_175 a,order_175_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_creator like @ord_creator_min 
and ord_creator like @ord_creator_max 
and ord_tkfs like @ord_tkfs_min 
and ord_tkfs like @ord_tkfs_max 
and ord_sfzhm like @ord_sfzhm_min 
and ord_sfzhm like @ord_sfzhm_max 
and ord_yxqh like @ord_yxqh_min 
and ord_yxqh like @ord_yxqh_max 
and ord_vipqh like @ord_vipqh_min 
and ord_vipqh like @ord_vipqh_max 
and ord_tkje>=@ord_tkje_min 
and ord_tkje<=@ord_tkje_max 
and ord_status like @ord_status_min 
and ord_status like @ord_status_max 
and ord_dpmc like @ord_dpmc_min 
and ord_dpmc like @ord_dpmc_max 
and ord_createdepart like @ord_createdepart_min 
and ord_createdepart like @ord_createdepart_max 
and ord_date>=@ord_date_min 
and ord_date<=@ord_date_max 
and ord_dh like @ord_dh_min 
and ord_dh like @ord_dh_max 
and ord_gmsj>=@ord_gmsj_min 
and ord_gmsj<=@ord_gmsj_max 
and ord_hz like @ord_hz_min 
and ord_hz like @ord_hz_max 
and ord_khx like @ord_khx_min 
and ord_khx like @ord_khx_max 
and ord_khxm like @ord_khxm_min 
and ord_khxm like @ord_khxm_max 
and ord_no like @ord_no_min 
and ord_no like @ord_no_max 
order by ord_date desc,ord_creator,ord_tkfs,ord_sfzhm,ord_yxqh,ord_vipqh,ord_tkje,ord_status,ord_dpmc,ord_createdepart,ord_dh,ord_gmsj desc,ord_hz,ord_khx,ord_khxm,ord_no
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_175 a,order_175_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_creator like @ord_creator_min 
and ord_creator like @ord_creator_max 
and ord_tkfs like @ord_tkfs_min 
and ord_tkfs like @ord_tkfs_max 
and ord_sfzhm like @ord_sfzhm_min 
and ord_sfzhm like @ord_sfzhm_max 
and ord_yxqh like @ord_yxqh_min 
and ord_yxqh like @ord_yxqh_max 
and ord_vipqh like @ord_vipqh_min 
and ord_vipqh like @ord_vipqh_max 
and ord_tkje>=@ord_tkje_min 
and ord_tkje<=@ord_tkje_max 
and ord_status like @ord_status_min 
and ord_status like @ord_status_max 
and ord_dpmc like @ord_dpmc_min 
and ord_dpmc like @ord_dpmc_max 
and ord_createdepart like @ord_createdepart_min 
and ord_createdepart like @ord_createdepart_max 
and ord_date>=@ord_date_min 
and ord_date<=@ord_date_max 
and ord_dh like @ord_dh_min 
and ord_dh like @ord_dh_max 
and ord_gmsj>=@ord_gmsj_min 
and ord_gmsj<=@ord_gmsj_max 
and ord_hz like @ord_hz_min 
and ord_hz like @ord_hz_max 
and ord_khx like @ord_khx_min 
and ord_khx like @ord_khx_max 
and ord_khxm like @ord_khxm_min 
and ord_khxm like @ord_khxm_max 
and ord_no like @ord_no_min 
and ord_no like @ord_no_max 
order by ord_date desc,ord_creator,ord_tkfs,ord_sfzhm,ord_yxqh,ord_vipqh,ord_tkje,ord_status,ord_dpmc,ord_createdepart,ord_dh,ord_gmsj desc,ord_hz,ord_khx,ord_khxm,ord_no
select count(1) resultcount  from datalinker where useruid=@useruid 
end else
begin
select count(1) cnt from order_175 a,order_175_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_creator like @ord_creator_min 
and ord_creator like @ord_creator_max 
and ord_tkfs like @ord_tkfs_min 
and ord_tkfs like @ord_tkfs_max 
and ord_sfzhm like @ord_sfzhm_min 
and ord_sfzhm like @ord_sfzhm_max 
and ord_yxqh like @ord_yxqh_min 
and ord_yxqh like @ord_yxqh_max 
and ord_vipqh like @ord_vipqh_min 
and ord_vipqh like @ord_vipqh_max 
and ord_tkje>=@ord_tkje_min 
and ord_tkje<=@ord_tkje_max 
and ord_status like @ord_status_min 
and ord_status like @ord_status_max 
and ord_dpmc like @ord_dpmc_min 
and ord_dpmc like @ord_dpmc_max 
and ord_createdepart like @ord_createdepart_min 
and ord_createdepart like @ord_createdepart_max 
and ord_date>=@ord_date_min 
and ord_date<=@ord_date_max 
and ord_dh like @ord_dh_min 
and ord_dh like @ord_dh_max 
and ord_gmsj>=@ord_gmsj_min 
and ord_gmsj<=@ord_gmsj_max 
and ord_hz like @ord_hz_min 
and ord_hz like @ord_hz_max 
and ord_khx like @ord_khx_min 
and ord_khx like @ord_khx_max 
and ord_khxm like @ord_khxm_min 
and ord_khxm like @ord_khxm_max 
and ord_no like @ord_no_min 
and ord_no like @ord_no_max 

-- 返回所有ID
insert into @pobjs(ordid) select top(@amount) ord_id from order_175 a,order_175_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_creator like @ord_creator_min 
and ord_creator like @ord_creator_max 
and ord_tkfs like @ord_tkfs_min 
and ord_tkfs like @ord_tkfs_max 
and ord_sfzhm like @ord_sfzhm_min 
and ord_sfzhm like @ord_sfzhm_max 
and ord_yxqh like @ord_yxqh_min 
and ord_yxqh like @ord_yxqh_max 
and ord_vipqh like @ord_vipqh_min 
and ord_vipqh like @ord_vipqh_max 
and ord_tkje>=@ord_tkje_min 
and ord_tkje<=@ord_tkje_max 
and ord_status like @ord_status_min 
and ord_status like @ord_status_max 
and ord_dpmc like @ord_dpmc_min 
and ord_dpmc like @ord_dpmc_max 
and ord_createdepart like @ord_createdepart_min 
and ord_createdepart like @ord_createdepart_max 
and ord_date>=@ord_date_min 
and ord_date<=@ord_date_max 
and ord_dh like @ord_dh_min 
and ord_dh like @ord_dh_max 
and ord_gmsj>=@ord_gmsj_min 
and ord_gmsj<=@ord_gmsj_max 
and ord_hz like @ord_hz_min 
and ord_hz like @ord_hz_max 
and ord_khx like @ord_khx_min 
and ord_khx like @ord_khx_max 
and ord_khxm like @ord_khxm_min 
and ord_khxm like @ord_khxm_max 
and ord_no like @ord_no_min 
and ord_no like @ord_no_max 
order by ord_date desc,ord_creator,ord_tkfs,ord_sfzhm,ord_yxqh,ord_vipqh,ord_tkje,ord_status,ord_dpmc,ord_createdepart,ord_dh,ord_gmsj desc,ord_hz,ord_khx,ord_khxm,ord_no
select ordid from @pobjs 
order by nid 
-- 返回第一页 
select top(@pagesize) a.* from order_175 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_175_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_175 a,order_175_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_creator like @ord_creator_min 
and ord_creator like @ord_creator_max 
and ord_tkfs like @ord_tkfs_min 
and ord_tkfs like @ord_tkfs_max 
and ord_sfzhm like @ord_sfzhm_min 
and ord_sfzhm like @ord_sfzhm_max 
and ord_yxqh like @ord_yxqh_min 
and ord_yxqh like @ord_yxqh_max 
and ord_vipqh like @ord_vipqh_min 
and ord_vipqh like @ord_vipqh_max 
and ord_tkje>=@ord_tkje_min 
and ord_tkje<=@ord_tkje_max 
and ord_status like @ord_status_min 
and ord_status like @ord_status_max 
and ord_dpmc like @ord_dpmc_min 
and ord_dpmc like @ord_dpmc_max 
and ord_createdepart like @ord_createdepart_min 
and ord_createdepart like @ord_createdepart_max 
and ord_date>=@ord_date_min 
and ord_date<=@ord_date_max 
and ord_dh like @ord_dh_min 
and ord_dh like @ord_dh_max 
and ord_gmsj>=@ord_gmsj_min 
and ord_gmsj<=@ord_gmsj_max 
and ord_hz like @ord_hz_min 
and ord_hz like @ord_hz_max 
and ord_khx like @ord_khx_min 
and ord_khx like @ord_khx_max 
and ord_khxm like @ord_khxm_min 
and ord_khxm like @ord_khxm_max 
and ord_no like @ord_no_min 
and ord_no like @ord_no_max 
order by ord_date desc,ord_creator,ord_tkfs,ord_sfzhm,ord_yxqh,ord_vipqh,ord_tkje,ord_status,ord_dpmc,ord_createdepart,ord_dh,ord_gmsj desc,ord_hz,ord_khx,ord_khxm,ord_no
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_175 a,order_175_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_creator like @ord_creator_min 
and ord_creator like @ord_creator_max 
and ord_tkfs like @ord_tkfs_min 
and ord_tkfs like @ord_tkfs_max 
and ord_sfzhm like @ord_sfzhm_min 
and ord_sfzhm like @ord_sfzhm_max 
and ord_yxqh like @ord_yxqh_min 
and ord_yxqh like @ord_yxqh_max 
and ord_vipqh like @ord_vipqh_min 
and ord_vipqh like @ord_vipqh_max 
and ord_tkje>=@ord_tkje_min 
and ord_tkje<=@ord_tkje_max 
and ord_status like @ord_status_min 
and ord_status like @ord_status_max 
and ord_dpmc like @ord_dpmc_min 
and ord_dpmc like @ord_dpmc_max 
and ord_createdepart like @ord_createdepart_min 
and ord_createdepart like @ord_createdepart_max 
and ord_date>=@ord_date_min 
and ord_date<=@ord_date_max 
and ord_dh like @ord_dh_min 
and ord_dh like @ord_dh_max 
and ord_gmsj>=@ord_gmsj_min 
and ord_gmsj<=@ord_gmsj_max 
and ord_hz like @ord_hz_min 
and ord_hz like @ord_hz_max 
and ord_khx like @ord_khx_min 
and ord_khx like @ord_khx_max 
and ord_khxm like @ord_khxm_min 
and ord_khxm like @ord_khxm_max 
and ord_no like @ord_no_min 
and ord_no like @ord_no_max 
order by ord_date desc,ord_creator,ord_tkfs,ord_sfzhm,ord_yxqh,ord_vipqh,ord_tkje,ord_status,ord_dpmc,ord_createdepart,ord_dh,ord_gmsj desc,ord_hz,ord_khx,ord_khxm,ord_no
select count(1) resultcount  from datalinker where useruid=@useruid 
end else
begin
select count(1) cnt from order_175 a,order_175_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_creator like @ord_creator_min 
and ord_creator like @ord_creator_max 
and ord_tkfs like @ord_tkfs_min 
and ord_tkfs like @ord_tkfs_max 
and ord_sfzhm like @ord_sfzhm_min 
and ord_sfzhm like @ord_sfzhm_max 
and ord_yxqh like @ord_yxqh_min 
and ord_yxqh like @ord_yxqh_max 
and ord_vipqh like @ord_vipqh_min 
and ord_vipqh like @ord_vipqh_max 
and ord_tkje>=@ord_tkje_min 
and ord_tkje<=@ord_tkje_max 
and ord_status like @ord_status_min 
and ord_status like @ord_status_max 
and ord_dpmc like @ord_dpmc_min 
and ord_dpmc like @ord_dpmc_max 
and ord_createdepart like @ord_createdepart_min 
and ord_createdepart like @ord_createdepart_max 
and ord_date>=@ord_date_min 
and ord_date<=@ord_date_max 
and ord_dh like @ord_dh_min 
and ord_dh like @ord_dh_max 
and ord_gmsj>=@ord_gmsj_min 
and ord_gmsj<=@ord_gmsj_max 
and ord_hz like @ord_hz_min 
and ord_hz like @ord_hz_max 
and ord_khx like @ord_khx_min 
and ord_khx like @ord_khx_max 
and ord_khxm like @ord_khxm_min 
and ord_khxm like @ord_khxm_max 
and ord_no like @ord_no_min 
and ord_no like @ord_no_max 

-- 返回所有ID
insert into @pobjs(ordid) select top(@amount) ord_id from order_175 a,order_175_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_creator like @ord_creator_min 
and ord_creator like @ord_creator_max 
and ord_tkfs like @ord_tkfs_min 
and ord_tkfs like @ord_tkfs_max 
and ord_sfzhm like @ord_sfzhm_min 
and ord_sfzhm like @ord_sfzhm_max 
and ord_yxqh like @ord_yxqh_min 
and ord_yxqh like @ord_yxqh_max 
and ord_vipqh like @ord_vipqh_min 
and ord_vipqh like @ord_vipqh_max 
and ord_tkje>=@ord_tkje_min 
and ord_tkje<=@ord_tkje_max 
and ord_status like @ord_status_min 
and ord_status like @ord_status_max 
and ord_dpmc like @ord_dpmc_min 
and ord_dpmc like @ord_dpmc_max 
and ord_createdepart like @ord_createdepart_min 
and ord_createdepart like @ord_createdepart_max 
and ord_date>=@ord_date_min 
and ord_date<=@ord_date_max 
and ord_dh like @ord_dh_min 
and ord_dh like @ord_dh_max 
and ord_gmsj>=@ord_gmsj_min 
and ord_gmsj<=@ord_gmsj_max 
and ord_hz like @ord_hz_min 
and ord_hz like @ord_hz_max 
and ord_khx like @ord_khx_min 
and ord_khx like @ord_khx_max 
and ord_khxm like @ord_khxm_min 
and ord_khxm like @ord_khxm_max 
and ord_no like @ord_no_min 
and ord_no like @ord_no_max 
order by ord_date desc,ord_creator,ord_tkfs,ord_sfzhm,ord_yxqh,ord_vipqh,ord_tkje,ord_status,ord_dpmc,ord_createdepart,ord_dh,ord_gmsj desc,ord_hz,ord_khx,ord_khxm,ord_no
select ordid from @pobjs 
order by nid 
-- 返回第一页 
select top(@pagesize) a.* from order_175 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_175_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_175 a,order_175_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_creator like @ord_creator_min 
and ord_creator like @ord_creator_max 
and ord_tkfs like @ord_tkfs_min 
and ord_tkfs like @ord_tkfs_max 
and ord_sfzhm like @ord_sfzhm_min 
and ord_sfzhm like @ord_sfzhm_max 
and ord_yxqh like @ord_yxqh_min 
and ord_yxqh like @ord_yxqh_max 
and ord_vipqh like @ord_vipqh_min 
and ord_vipqh like @ord_vipqh_max 
and ord_tkje>=@ord_tkje_min 
and ord_tkje<=@ord_tkje_max 
and ord_status like @ord_status_min 
and ord_status like @ord_status_max 
and ord_dpmc like @ord_dpmc_min 
and ord_dpmc like @ord_dpmc_max 
and ord_createdepart like @ord_createdepart_min 
and ord_createdepart like @ord_createdepart_max 
and ord_date>=@ord_date_min 
and ord_date<=@ord_date_max 
and ord_dh like @ord_dh_min 
and ord_dh like @ord_dh_max 
and ord_gmsj>=@ord_gmsj_min 
and ord_gmsj<=@ord_gmsj_max 
and ord_hz like @ord_hz_min 
and ord_hz like @ord_hz_max 
and ord_khx like @ord_khx_min 
and ord_khx like @ord_khx_max 
and ord_khxm like @ord_khxm_min 
and ord_khxm like @ord_khxm_max 
and ord_no like @ord_no_min 
and ord_no like @ord_no_max 
order by ord_date desc,ord_creator,ord_tkfs,ord_sfzhm,ord_yxqh,ord_vipqh,ord_tkje,ord_status,ord_dpmc,ord_createdepart,ord_dh,ord_gmsj desc,ord_hz,ord_khx,ord_khxm,ord_no
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_175 a,order_175_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_creator like @ord_creator_min 
and ord_creator like @ord_creator_max 
and ord_tkfs like @ord_tkfs_min 
and ord_tkfs like @ord_tkfs_max 
and ord_sfzhm like @ord_sfzhm_min 
and ord_sfzhm like @ord_sfzhm_max 
and ord_yxqh like @ord_yxqh_min 
and ord_yxqh like @ord_yxqh_max 
and ord_vipqh like @ord_vipqh_min 
and ord_vipqh like @ord_vipqh_max 
and ord_tkje>=@ord_tkje_min 
and ord_tkje<=@ord_tkje_max 
and ord_status like @ord_status_min 
and ord_status like @ord_status_max 
and ord_dpmc like @ord_dpmc_min 
and ord_dpmc like @ord_dpmc_max 
and ord_createdepart like @ord_createdepart_min 
and ord_createdepart like @ord_createdepart_max 
and ord_date>=@ord_date_min 
and ord_date<=@ord_date_max 
and ord_dh like @ord_dh_min 
and ord_dh like @ord_dh_max 
and ord_gmsj>=@ord_gmsj_min 
and ord_gmsj<=@ord_gmsj_max 
and ord_hz like @ord_hz_min 
and ord_hz like @ord_hz_max 
and ord_khx like @ord_khx_min 
and ord_khx like @ord_khx_max 
and ord_khxm like @ord_khxm_min 
and ord_khxm like @ord_khxm_max 
and ord_no like @ord_no_min 
and ord_no like @ord_no_max 
order by ord_date desc,ord_creator,ord_tkfs,ord_sfzhm,ord_yxqh,ord_vipqh,ord_tkje,ord_status,ord_dpmc,ord_createdepart,ord_dh,ord_gmsj desc,ord_hz,ord_khx,ord_khxm,ord_no
select count(1) resultcount  from datalinker where useruid=@useruid 
end else
begin
select count(1) cnt from order_175 a,order_175_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_creator like @ord_creator_min 
and ord_creator like @ord_creator_max 
and ord_tkfs like @ord_tkfs_min 
and ord_tkfs like @ord_tkfs_max 
and ord_sfzhm like @ord_sfzhm_min 
and ord_sfzhm like @ord_sfzhm_max 
and ord_yxqh like @ord_yxqh_min 
and ord_yxqh like @ord_yxqh_max 
and ord_vipqh like @ord_vipqh_min 
and ord_vipqh like @ord_vipqh_max 
and ord_tkje>=@ord_tkje_min 
and ord_tkje<=@ord_tkje_max 
and ord_status like @ord_status_min 
and ord_status like @ord_status_max 
and ord_dpmc like @ord_dpmc_min 
and ord_dpmc like @ord_dpmc_max 
and ord_createdepart like @ord_createdepart_min 
and ord_createdepart like @ord_createdepart_max 
and ord_date>=@ord_date_min 
and ord_date<=@ord_date_max 
and ord_dh like @ord_dh_min 
and ord_dh like @ord_dh_max 
and ord_gmsj>=@ord_gmsj_min 
and ord_gmsj<=@ord_gmsj_max 
and ord_hz like @ord_hz_min 
and ord_hz like @ord_hz_max 
and ord_khx like @ord_khx_min 
and ord_khx like @ord_khx_max 
and ord_khxm like @ord_khxm_min 
and ord_khxm like @ord_khxm_max 
and ord_no like @ord_no_min 
and ord_no like @ord_no_max 

-- 返回所有ID
insert into @pobjs(ordid) select top(@amount) ord_id from order_175 a,order_175_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_creator like @ord_creator_min 
and ord_creator like @ord_creator_max 
and ord_tkfs like @ord_tkfs_min 
and ord_tkfs like @ord_tkfs_max 
and ord_sfzhm like @ord_sfzhm_min 
and ord_sfzhm like @ord_sfzhm_max 
and ord_yxqh like @ord_yxqh_min 
and ord_yxqh like @ord_yxqh_max 
and ord_vipqh like @ord_vipqh_min 
and ord_vipqh like @ord_vipqh_max 
and ord_tkje>=@ord_tkje_min 
and ord_tkje<=@ord_tkje_max 
and ord_status like @ord_status_min 
and ord_status like @ord_status_max 
and ord_dpmc like @ord_dpmc_min 
and ord_dpmc like @ord_dpmc_max 
and ord_createdepart like @ord_createdepart_min 
and ord_createdepart like @ord_createdepart_max 
and ord_date>=@ord_date_min 
and ord_date<=@ord_date_max 
and ord_dh like @ord_dh_min 
and ord_dh like @ord_dh_max 
and ord_gmsj>=@ord_gmsj_min 
and ord_gmsj<=@ord_gmsj_max 
and ord_hz like @ord_hz_min 
and ord_hz like @ord_hz_max 
and ord_khx like @ord_khx_min 
and ord_khx like @ord_khx_max 
and ord_khxm like @ord_khxm_min 
and ord_khxm like @ord_khxm_max 
and ord_no like @ord_no_min 
and ord_no like @ord_no_max 
order by ord_date desc,ord_creator,ord_tkfs,ord_sfzhm,ord_yxqh,ord_vipqh,ord_tkje,ord_status,ord_dpmc,ord_createdepart,ord_dh,ord_gmsj desc,ord_hz,ord_khx,ord_khxm,ord_no
select ordid from @pobjs 
order by nid 
-- 返回第一页 
select top(@pagesize) a.* from order_175 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_175_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_175 a,order_175_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_creator like @ord_creator_min 
and ord_creator like @ord_creator_max 
and ord_tkfs like @ord_tkfs_min 
and ord_tkfs like @ord_tkfs_max 
and ord_sfzhm like @ord_sfzhm_min 
and ord_sfzhm like @ord_sfzhm_max 
and ord_yxqh like @ord_yxqh_min 
and ord_yxqh like @ord_yxqh_max 
and ord_vipqh like @ord_vipqh_min 
and ord_vipqh like @ord_vipqh_max 
and ord_tkje>=@ord_tkje_min 
and ord_tkje<=@ord_tkje_max 
and ord_status like @ord_status_min 
and ord_status like @ord_status_max 
and ord_dpmc like @ord_dpmc_min 
and ord_dpmc like @ord_dpmc_max 
and ord_createdepart like @ord_createdepart_min 
and ord_createdepart like @ord_createdepart_max 
and ord_date>=@ord_date_min 
and ord_date<=@ord_date_max 
and ord_dh like @ord_dh_min 
and ord_dh like @ord_dh_max 
and ord_gmsj>=@ord_gmsj_min 
and ord_gmsj<=@ord_gmsj_max 
and ord_hz like @ord_hz_min 
and ord_hz like @ord_hz_max 
and ord_khx like @ord_khx_min 
and ord_khx like @ord_khx_max 
and ord_khxm like @ord_khxm_min 
and ord_khxm like @ord_khxm_max 
and ord_no like @ord_no_min 
and ord_no like @ord_no_max 
order by ord_date desc,ord_creator,ord_tkfs,ord_sfzhm,ord_yxqh,ord_vipqh,ord_tkje,ord_status,ord_dpmc,ord_createdepart,ord_dh,ord_gmsj desc,ord_hz,ord_khx,ord_khxm,ord_no
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_175 a,order_175_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_creator like @ord_creator_min 
and ord_creator like @ord_creator_max 
and ord_tkfs like @ord_tkfs_min 
and ord_tkfs like @ord_tkfs_max 
and ord_sfzhm like @ord_sfzhm_min 
and ord_sfzhm like @ord_sfzhm_max 
and ord_yxqh like @ord_yxqh_min 
and ord_yxqh like @ord_yxqh_max 
and ord_vipqh like @ord_vipqh_min 
and ord_vipqh like @ord_vipqh_max 
and ord_tkje>=@ord_tkje_min 
and ord_tkje<=@ord_tkje_max 
and ord_status like @ord_status_min 
and ord_status like @ord_status_max 
and ord_dpmc like @ord_dpmc_min 
and ord_dpmc like @ord_dpmc_max 
and ord_createdepart like @ord_createdepart_min 
and ord_createdepart like @ord_createdepart_max 
and ord_date>=@ord_date_min 
and ord_date<=@ord_date_max 
and ord_dh like @ord_dh_min 
and ord_dh like @ord_dh_max 
and ord_gmsj>=@ord_gmsj_min 
and ord_gmsj<=@ord_gmsj_max 
and ord_hz like @ord_hz_min 
and ord_hz like @ord_hz_max 
and ord_khx like @ord_khx_min 
and ord_khx like @ord_khx_max 
and ord_khxm like @ord_khxm_min 
and ord_khxm like @ord_khxm_max 
and ord_no like @ord_no_min 
and ord_no like @ord_no_max 
order by ord_date desc,ord_creator,ord_tkfs,ord_sfzhm,ord_yxqh,ord_vipqh,ord_tkje,ord_status,ord_dpmc,ord_createdepart,ord_dh,ord_gmsj desc,ord_hz,ord_khx,ord_khxm,ord_no
select count(1) resultcount  from datalinker where useruid=@useruid 
end else
begin
select count(1) cnt from order_175 a,order_175_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_creator like @ord_creator_min 
and ord_creator like @ord_creator_max 
and ord_tkfs like @ord_tkfs_min 
and ord_tkfs like @ord_tkfs_max 
and ord_sfzhm like @ord_sfzhm_min 
and ord_sfzhm like @ord_sfzhm_max 
and ord_yxqh like @ord_yxqh_min 
and ord_yxqh like @ord_yxqh_max 
and ord_vipqh like @ord_vipqh_min 
and ord_vipqh like @ord_vipqh_max 
and ord_tkje>=@ord_tkje_min 
and ord_tkje<=@ord_tkje_max 
and ord_status like @ord_status_min 
and ord_status like @ord_status_max 
and ord_dpmc like @ord_dpmc_min 
and ord_dpmc like @ord_dpmc_max 
and ord_createdepart like @ord_createdepart_min 
and ord_createdepart like @ord_createdepart_max 
and ord_date>=@ord_date_min 
and ord_date<=@ord_date_max 
and ord_dh like @ord_dh_min 
and ord_dh like @ord_dh_max 
and ord_gmsj>=@ord_gmsj_min 
and ord_gmsj<=@ord_gmsj_max 
and ord_hz like @ord_hz_min 
and ord_hz like @ord_hz_max 
and ord_khx like @ord_khx_min 
and ord_khx like @ord_khx_max 
and ord_khxm like @ord_khxm_min 
and ord_khxm like @ord_khxm_max 
and ord_no like @ord_no_min 
and ord_no like @ord_no_max 

-- 返回所有ID
insert into @pobjs(ordid) select top(@amount) ord_id from order_175 a,order_175_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_creator like @ord_creator_min 
and ord_creator like @ord_creator_max 
and ord_tkfs like @ord_tkfs_min 
and ord_tkfs like @ord_tkfs_max 
and ord_sfzhm like @ord_sfzhm_min 
and ord_sfzhm like @ord_sfzhm_max 
and ord_yxqh like @ord_yxqh_min 
and ord_yxqh like @ord_yxqh_max 
and ord_vipqh like @ord_vipqh_min 
and ord_vipqh like @ord_vipqh_max 
and ord_tkje>=@ord_tkje_min 
and ord_tkje<=@ord_tkje_max 
and ord_status like @ord_status_min 
and ord_status like @ord_status_max 
and ord_dpmc like @ord_dpmc_min 
and ord_dpmc like @ord_dpmc_max 
and ord_createdepart like @ord_createdepart_min 
and ord_createdepart like @ord_createdepart_max 
and ord_date>=@ord_date_min 
and ord_date<=@ord_date_max 
and ord_dh like @ord_dh_min 
and ord_dh like @ord_dh_max 
and ord_gmsj>=@ord_gmsj_min 
and ord_gmsj<=@ord_gmsj_max 
and ord_hz like @ord_hz_min 
and ord_hz like @ord_hz_max 
and ord_khx like @ord_khx_min 
and ord_khx like @ord_khx_max 
and ord_khxm like @ord_khxm_min 
and ord_khxm like @ord_khxm_max 
and ord_no like @ord_no_min 
and ord_no like @ord_no_max 
order by ord_date desc,ord_creator,ord_tkfs,ord_sfzhm,ord_yxqh,ord_vipqh,ord_tkje,ord_status,ord_dpmc,ord_createdepart,ord_dh,ord_gmsj desc,ord_hz,ord_khx,ord_khxm,ord_no
select ordid from @pobjs 
order by nid 
-- 返回第一页 
select top(@pagesize) a.* from order_175 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_175_users a , @pobjs 
where ordp_ordid=ordid 
and nid<=@pagesize 
and ordp_cuid=@useruid 
end 
end 
set nocount off end