IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[dbo].[order_188_query_simple]') AND type = 'P')
DROP PROCEDURE [dbo].[order_188_query_simple]
GO
CREATE  procedure order_188_query_simple(
@cmpid int,@branchid int,@userdpid int,@userotid int ,@useruid int ,@bizid int ,@finished int ,@status nvarchar(50),@pagesize int , @pagecount int , @pageobjids varchar(8000),@date1 datetime ,@date2 datetime ,@key1 nvarchar(50),@key2 nvarchar(50),@key3 nvarchar(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_188 a, @pobjs
where ord_id=ordid
order by nid 
select a.* from order_188_users a , @pobjs 
where ordp_ordid=ordid and ordp_cuid=@useruid
return 
end 
if (@status is null or @status = '_none_') set @status = '' 

 

if (@key1='') set @key1='%' 
if (charindex('%',@key1)<=0 and @key1>'') set @key1='%'+@key1+'%'

if (@key2='') set @key2='%' 
if (charindex('%',@key2)<=0 and @key2>'') set @key2='%'+@key2+'%'

if (@key3='') set @key3='%' 
if (charindex('%',@key3)<=0 and @key3>'') set @key3='%'+@key3+'%'

if (@finished = -11)
begin
if (@pagesize=10000)  -- 下载
begin
select a.* from order_188 a,order_188_users 
where a.ord_cmpid=@cmpid 
and a.ord_id=ordp_ordid 
and ordp_type='bizview' 
and ordp_cuid=@useruid 
and (a.ord_status=@status or @status='') 
and a.ord_finished > 0 
and (
 (ord_dpzt like @key1 and ord_dpzt like @key2 and ord_dpzt like @key3 ) or 
 (ord_fzrcode like @key1 and ord_fzrcode like @key2 and ord_fzrcode like @key3 ) or 
 (ord_pqzjcode like @key1 and ord_pqzjcode like @key2 and ord_pqzjcode like @key3 ) or 
 (ord_dz like @key1 and ord_dz like @key2 and ord_dz like @key3 ) or 
 (ord_fzcode like @key1 and ord_fzcode like @key2 and ord_fzcode like @key3 ) or 
 (ord_fz like @key1 and ord_fz like @key2 and ord_fz like @key3 ) or 
 (ord_dzcode like @key1 and ord_dzcode like @key2 and ord_dzcode like @key3 ) or 
 (ord_empname like @key1 and ord_empname like @key2 and ord_empname like @key3 ) or 
 (ord_dpfzr like @key1 and ord_dpfzr like @key2 and ord_dpfzr like @key3 ) or 
 (ord_dplx like @key1 and ord_dplx like @key2 and ord_dplx like @key3 ) or 
 (ord_no like @key1 and ord_no like @key2 and ord_no like @key3 ) or 
 (ord_dpdz like @key1 and ord_dpdz like @key2 and ord_dpdz like @key3 ) or 
 (ord_dpmc like @key1 and ord_dpmc like @key2 and ord_dpmc like @key3 ) or 
 (ord_pqjlcode like @key1 and ord_pqjlcode like @key2 and ord_pqjlcode like @key3 ) or 
 (ord_dpbh like @key1 and ord_dpbh like @key2 and ord_dpbh like @key3 ) or 
 (ord_szjxs like @key1 and ord_szjxs like @key2 and ord_szjxs like @key3 ) or 
 (ord_szfgs like @key1 and ord_szfgs like @key2 and ord_szfgs like @key3 ) or 
 (ord_pqdd like @key1 and ord_pqdd like @key2 and ord_pqdd like @key3 ) or 
 (ord_pqddcode like @key1 and ord_pqddcode like @key2 and ord_pqddcode like @key3 ) or 
 (ord_pqzj like @key1 and ord_pqzj like @key2 and ord_pqzj like @key3 ) or 
 (ord_qx like @key1 and ord_qx like @key2 and ord_qx like @key3 ) or 
 (ord_lxrdh like @key1 and ord_lxrdh like @key2 and ord_lxrdh like @key3 ) or 
 (ord_pqjl like @key1 and ord_pqjl like @key2 and ord_pqjl like @key3 ) or 
 (ord_posid like @key1 and ord_posid like @key2 and ord_posid like @key3 ) or 
 (ord_jmssj like @key1 and ord_jmssj like @key2 and ord_jmssj like @key3 ) or 
 (ord_status like @key1 and ord_status like @key2 and ord_status like @key3 ) or 
 (ord_jmsmc like @key1 and ord_jmsmc like @key2 and ord_jmsmc like @key3 ) or 
 (ord_jmslxr like @key1 and ord_jmslxr like @key2 and ord_jmslxr like @key3 ) or 
 (ord_jmsdh like @key1 and ord_jmsdh like @key2 and ord_jmsdh like @key3 ) or 
 (ord_htbh like @key1 and ord_htbh like @key2 and ord_htbh like @key3 ) or 
 (ord_kdsj like @key1 and ord_kdsj like @key2 and ord_kdsj like @key3 ) ) and 
(ord_gdsj >= @date1 and ord_gdsj <= @date2 ) 
order by ord_date desc,ord_dpzt,ord_fzrcode,ord_pqzjcode,ord_gdsj desc,ord_dz,ord_fzcode,ord_fz,ord_dzcode,ord_empname,ord_dpfzr,ord_dplx,ord_no,ord_dpdz,ord_dpmc,ord_pqjlcode,ord_dpbh,ord_szjxs,ord_szfgs,ord_pqdd,ord_pqddcode,ord_pqzj,ord_qx,ord_lxrdh,ord_pqjl,ord_posid,ord_jmssj,ord_status,ord_jmsmc,ord_jmslxr,ord_jmsdh,ord_htbh,ord_kdsj desc
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_188 a,order_188_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_dpzt like @key1 and ord_dpzt like @key2 and ord_dpzt like @key3 ) or 
 (ord_fzrcode like @key1 and ord_fzrcode like @key2 and ord_fzrcode like @key3 ) or 
 (ord_pqzjcode like @key1 and ord_pqzjcode like @key2 and ord_pqzjcode like @key3 ) or 
 (ord_dz like @key1 and ord_dz like @key2 and ord_dz like @key3 ) or 
 (ord_fzcode like @key1 and ord_fzcode like @key2 and ord_fzcode like @key3 ) or 
 (ord_fz like @key1 and ord_fz like @key2 and ord_fz like @key3 ) or 
 (ord_dzcode like @key1 and ord_dzcode like @key2 and ord_dzcode like @key3 ) or 
 (ord_empname like @key1 and ord_empname like @key2 and ord_empname like @key3 ) or 
 (ord_dpfzr like @key1 and ord_dpfzr like @key2 and ord_dpfzr like @key3 ) or 
 (ord_dplx like @key1 and ord_dplx like @key2 and ord_dplx like @key3 ) or 
 (ord_no like @key1 and ord_no like @key2 and ord_no like @key3 ) or 
 (ord_dpdz like @key1 and ord_dpdz like @key2 and ord_dpdz like @key3 ) or 
 (ord_dpmc like @key1 and ord_dpmc like @key2 and ord_dpmc like @key3 ) or 
 (ord_pqjlcode like @key1 and ord_pqjlcode like @key2 and ord_pqjlcode like @key3 ) or 
 (ord_dpbh like @key1 and ord_dpbh like @key2 and ord_dpbh like @key3 ) or 
 (ord_szjxs like @key1 and ord_szjxs like @key2 and ord_szjxs like @key3 ) or 
 (ord_szfgs like @key1 and ord_szfgs like @key2 and ord_szfgs like @key3 ) or 
 (ord_pqdd like @key1 and ord_pqdd like @key2 and ord_pqdd like @key3 ) or 
 (ord_pqddcode like @key1 and ord_pqddcode like @key2 and ord_pqddcode like @key3 ) or 
 (ord_pqzj like @key1 and ord_pqzj like @key2 and ord_pqzj like @key3 ) or 
 (ord_qx like @key1 and ord_qx like @key2 and ord_qx like @key3 ) or 
 (ord_lxrdh like @key1 and ord_lxrdh like @key2 and ord_lxrdh like @key3 ) or 
 (ord_pqjl like @key1 and ord_pqjl like @key2 and ord_pqjl like @key3 ) or 
 (ord_posid like @key1 and ord_posid like @key2 and ord_posid like @key3 ) or 
 (ord_jmssj like @key1 and ord_jmssj like @key2 and ord_jmssj like @key3 ) or 
 (ord_status like @key1 and ord_status like @key2 and ord_status like @key3 ) or 
 (ord_jmsmc like @key1 and ord_jmsmc like @key2 and ord_jmsmc like @key3 ) or 
 (ord_jmslxr like @key1 and ord_jmslxr like @key2 and ord_jmslxr like @key3 ) or 
 (ord_jmsdh like @key1 and ord_jmsdh like @key2 and ord_jmsdh like @key3 ) or 
 (ord_htbh like @key1 and ord_htbh like @key2 and ord_htbh like @key3 ) or 
 (ord_kdsj like @key1 and ord_kdsj like @key2 and ord_kdsj like @key3 ) ) and 
(ord_gdsj >= @date1 and ord_gdsj <= @date2 ) 
order by ord_date desc,ord_dpzt,ord_fzrcode,ord_pqzjcode,ord_gdsj desc,ord_dz,ord_fzcode,ord_fz,ord_dzcode,ord_empname,ord_dpfzr,ord_dplx,ord_no,ord_dpdz,ord_dpmc,ord_pqjlcode,ord_dpbh,ord_szjxs,ord_szfgs,ord_pqdd,ord_pqddcode,ord_pqzj,ord_qx,ord_lxrdh,ord_pqjl,ord_posid,ord_jmssj,ord_status,ord_jmsmc,ord_jmslxr,ord_jmsdh,ord_htbh,ord_kdsj desc
select count(1) resultcount  from datalinker where useruid=@useruid 
end else
begin
select count(1) cnt from order_188 a,order_188_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_dpzt like @key1 and ord_dpzt like @key2 and ord_dpzt like @key3 ) or 
 (ord_fzrcode like @key1 and ord_fzrcode like @key2 and ord_fzrcode like @key3 ) or 
 (ord_pqzjcode like @key1 and ord_pqzjcode like @key2 and ord_pqzjcode like @key3 ) or 
 (ord_dz like @key1 and ord_dz like @key2 and ord_dz like @key3 ) or 
 (ord_fzcode like @key1 and ord_fzcode like @key2 and ord_fzcode like @key3 ) or 
 (ord_fz like @key1 and ord_fz like @key2 and ord_fz like @key3 ) or 
 (ord_dzcode like @key1 and ord_dzcode like @key2 and ord_dzcode like @key3 ) or 
 (ord_empname like @key1 and ord_empname like @key2 and ord_empname like @key3 ) or 
 (ord_dpfzr like @key1 and ord_dpfzr like @key2 and ord_dpfzr like @key3 ) or 
 (ord_dplx like @key1 and ord_dplx like @key2 and ord_dplx like @key3 ) or 
 (ord_no like @key1 and ord_no like @key2 and ord_no like @key3 ) or 
 (ord_dpdz like @key1 and ord_dpdz like @key2 and ord_dpdz like @key3 ) or 
 (ord_dpmc like @key1 and ord_dpmc like @key2 and ord_dpmc like @key3 ) or 
 (ord_pqjlcode like @key1 and ord_pqjlcode like @key2 and ord_pqjlcode like @key3 ) or 
 (ord_dpbh like @key1 and ord_dpbh like @key2 and ord_dpbh like @key3 ) or 
 (ord_szjxs like @key1 and ord_szjxs like @key2 and ord_szjxs like @key3 ) or 
 (ord_szfgs like @key1 and ord_szfgs like @key2 and ord_szfgs like @key3 ) or 
 (ord_pqdd like @key1 and ord_pqdd like @key2 and ord_pqdd like @key3 ) or 
 (ord_pqddcode like @key1 and ord_pqddcode like @key2 and ord_pqddcode like @key3 ) or 
 (ord_pqzj like @key1 and ord_pqzj like @key2 and ord_pqzj like @key3 ) or 
 (ord_qx like @key1 and ord_qx like @key2 and ord_qx like @key3 ) or 
 (ord_lxrdh like @key1 and ord_lxrdh like @key2 and ord_lxrdh like @key3 ) or 
 (ord_pqjl like @key1 and ord_pqjl like @key2 and ord_pqjl like @key3 ) or 
 (ord_posid like @key1 and ord_posid like @key2 and ord_posid like @key3 ) or 
 (ord_jmssj like @key1 and ord_jmssj like @key2 and ord_jmssj like @key3 ) or 
 (ord_status like @key1 and ord_status like @key2 and ord_status like @key3 ) or 
 (ord_jmsmc like @key1 and ord_jmsmc like @key2 and ord_jmsmc like @key3 ) or 
 (ord_jmslxr like @key1 and ord_jmslxr like @key2 and ord_jmslxr like @key3 ) or 
 (ord_jmsdh like @key1 and ord_jmsdh like @key2 and ord_jmsdh like @key3 ) or 
 (ord_htbh like @key1 and ord_htbh like @key2 and ord_htbh like @key3 ) or 
 (ord_kdsj like @key1 and ord_kdsj like @key2 and ord_kdsj like @key3 ) ) and 
(ord_gdsj >= @date1 and ord_gdsj <= @date2 ) 

-- 返回所有ID
insert into @pobjs(ordid) select top(@amount) ord_id from order_188 a,order_188_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_dpzt like @key1 and ord_dpzt like @key2 and ord_dpzt like @key3 ) or 
 (ord_fzrcode like @key1 and ord_fzrcode like @key2 and ord_fzrcode like @key3 ) or 
 (ord_pqzjcode like @key1 and ord_pqzjcode like @key2 and ord_pqzjcode like @key3 ) or 
 (ord_dz like @key1 and ord_dz like @key2 and ord_dz like @key3 ) or 
 (ord_fzcode like @key1 and ord_fzcode like @key2 and ord_fzcode like @key3 ) or 
 (ord_fz like @key1 and ord_fz like @key2 and ord_fz like @key3 ) or 
 (ord_dzcode like @key1 and ord_dzcode like @key2 and ord_dzcode like @key3 ) or 
 (ord_empname like @key1 and ord_empname like @key2 and ord_empname like @key3 ) or 
 (ord_dpfzr like @key1 and ord_dpfzr like @key2 and ord_dpfzr like @key3 ) or 
 (ord_dplx like @key1 and ord_dplx like @key2 and ord_dplx like @key3 ) or 
 (ord_no like @key1 and ord_no like @key2 and ord_no like @key3 ) or 
 (ord_dpdz like @key1 and ord_dpdz like @key2 and ord_dpdz like @key3 ) or 
 (ord_dpmc like @key1 and ord_dpmc like @key2 and ord_dpmc like @key3 ) or 
 (ord_pqjlcode like @key1 and ord_pqjlcode like @key2 and ord_pqjlcode like @key3 ) or 
 (ord_dpbh like @key1 and ord_dpbh like @key2 and ord_dpbh like @key3 ) or 
 (ord_szjxs like @key1 and ord_szjxs like @key2 and ord_szjxs like @key3 ) or 
 (ord_szfgs like @key1 and ord_szfgs like @key2 and ord_szfgs like @key3 ) or 
 (ord_pqdd like @key1 and ord_pqdd like @key2 and ord_pqdd like @key3 ) or 
 (ord_pqddcode like @key1 and ord_pqddcode like @key2 and ord_pqddcode like @key3 ) or 
 (ord_pqzj like @key1 and ord_pqzj like @key2 and ord_pqzj like @key3 ) or 
 (ord_qx like @key1 and ord_qx like @key2 and ord_qx like @key3 ) or 
 (ord_lxrdh like @key1 and ord_lxrdh like @key2 and ord_lxrdh like @key3 ) or 
 (ord_pqjl like @key1 and ord_pqjl like @key2 and ord_pqjl like @key3 ) or 
 (ord_posid like @key1 and ord_posid like @key2 and ord_posid like @key3 ) or 
 (ord_jmssj like @key1 and ord_jmssj like @key2 and ord_jmssj like @key3 ) or 
 (ord_status like @key1 and ord_status like @key2 and ord_status like @key3 ) or 
 (ord_jmsmc like @key1 and ord_jmsmc like @key2 and ord_jmsmc like @key3 ) or 
 (ord_jmslxr like @key1 and ord_jmslxr like @key2 and ord_jmslxr like @key3 ) or 
 (ord_jmsdh like @key1 and ord_jmsdh like @key2 and ord_jmsdh like @key3 ) or 
 (ord_htbh like @key1 and ord_htbh like @key2 and ord_htbh like @key3 ) or 
 (ord_kdsj like @key1 and ord_kdsj like @key2 and ord_kdsj like @key3 ) ) and 
(ord_gdsj >= @date1 and ord_gdsj <= @date2 ) 
order by ord_date desc,ord_dpzt,ord_fzrcode,ord_pqzjcode,ord_gdsj desc,ord_dz,ord_fzcode,ord_fz,ord_dzcode,ord_empname,ord_dpfzr,ord_dplx,ord_no,ord_dpdz,ord_dpmc,ord_pqjlcode,ord_dpbh,ord_szjxs,ord_szfgs,ord_pqdd,ord_pqddcode,ord_pqzj,ord_qx,ord_lxrdh,ord_pqjl,ord_posid,ord_jmssj,ord_status,ord_jmsmc,ord_jmslxr,ord_jmsdh,ord_htbh,ord_kdsj desc
select ordid from @pobjs 
order by nid 
-- 返回第一页 
select top(@pagesize) a.* from order_188 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_188_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_188 a,order_188_users 
where a.ord_cmpid=@cmpid 
and a.ord_id=ordp_ordid 
and ordp_type='bizview' 
and ordp_cuid=@useruid 
and (a.ord_status=@status or @status='') 
and (a.ord_finished>0 and a.ord_createcuid=@useruid) 
and (
 (ord_dpzt like @key1 and ord_dpzt like @key2 and ord_dpzt like @key3 ) or 
 (ord_fzrcode like @key1 and ord_fzrcode like @key2 and ord_fzrcode like @key3 ) or 
 (ord_pqzjcode like @key1 and ord_pqzjcode like @key2 and ord_pqzjcode like @key3 ) or 
 (ord_dz like @key1 and ord_dz like @key2 and ord_dz like @key3 ) or 
 (ord_fzcode like @key1 and ord_fzcode like @key2 and ord_fzcode like @key3 ) or 
 (ord_fz like @key1 and ord_fz like @key2 and ord_fz like @key3 ) or 
 (ord_dzcode like @key1 and ord_dzcode like @key2 and ord_dzcode like @key3 ) or 
 (ord_empname like @key1 and ord_empname like @key2 and ord_empname like @key3 ) or 
 (ord_dpfzr like @key1 and ord_dpfzr like @key2 and ord_dpfzr like @key3 ) or 
 (ord_dplx like @key1 and ord_dplx like @key2 and ord_dplx like @key3 ) or 
 (ord_no like @key1 and ord_no like @key2 and ord_no like @key3 ) or 
 (ord_dpdz like @key1 and ord_dpdz like @key2 and ord_dpdz like @key3 ) or 
 (ord_dpmc like @key1 and ord_dpmc like @key2 and ord_dpmc like @key3 ) or 
 (ord_pqjlcode like @key1 and ord_pqjlcode like @key2 and ord_pqjlcode like @key3 ) or 
 (ord_dpbh like @key1 and ord_dpbh like @key2 and ord_dpbh like @key3 ) or 
 (ord_szjxs like @key1 and ord_szjxs like @key2 and ord_szjxs like @key3 ) or 
 (ord_szfgs like @key1 and ord_szfgs like @key2 and ord_szfgs like @key3 ) or 
 (ord_pqdd like @key1 and ord_pqdd like @key2 and ord_pqdd like @key3 ) or 
 (ord_pqddcode like @key1 and ord_pqddcode like @key2 and ord_pqddcode like @key3 ) or 
 (ord_pqzj like @key1 and ord_pqzj like @key2 and ord_pqzj like @key3 ) or 
 (ord_qx like @key1 and ord_qx like @key2 and ord_qx like @key3 ) or 
 (ord_lxrdh like @key1 and ord_lxrdh like @key2 and ord_lxrdh like @key3 ) or 
 (ord_pqjl like @key1 and ord_pqjl like @key2 and ord_pqjl like @key3 ) or 
 (ord_posid like @key1 and ord_posid like @key2 and ord_posid like @key3 ) or 
 (ord_jmssj like @key1 and ord_jmssj like @key2 and ord_jmssj like @key3 ) or 
 (ord_status like @key1 and ord_status like @key2 and ord_status like @key3 ) or 
 (ord_jmsmc like @key1 and ord_jmsmc like @key2 and ord_jmsmc like @key3 ) or 
 (ord_jmslxr like @key1 and ord_jmslxr like @key2 and ord_jmslxr like @key3 ) or 
 (ord_jmsdh like @key1 and ord_jmsdh like @key2 and ord_jmsdh like @key3 ) or 
 (ord_htbh like @key1 and ord_htbh like @key2 and ord_htbh like @key3 ) or 
 (ord_kdsj like @key1 and ord_kdsj like @key2 and ord_kdsj like @key3 ) ) and 
(ord_gdsj >= @date1 and ord_gdsj <= @date2 ) 
order by ord_date desc,ord_dpzt,ord_fzrcode,ord_pqzjcode,ord_gdsj desc,ord_dz,ord_fzcode,ord_fz,ord_dzcode,ord_empname,ord_dpfzr,ord_dplx,ord_no,ord_dpdz,ord_dpmc,ord_pqjlcode,ord_dpbh,ord_szjxs,ord_szfgs,ord_pqdd,ord_pqddcode,ord_pqzj,ord_qx,ord_lxrdh,ord_pqjl,ord_posid,ord_jmssj,ord_status,ord_jmsmc,ord_jmslxr,ord_jmsdh,ord_htbh,ord_kdsj desc
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_188 a,order_188_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_dpzt like @key1 and ord_dpzt like @key2 and ord_dpzt like @key3 ) or 
 (ord_fzrcode like @key1 and ord_fzrcode like @key2 and ord_fzrcode like @key3 ) or 
 (ord_pqzjcode like @key1 and ord_pqzjcode like @key2 and ord_pqzjcode like @key3 ) or 
 (ord_dz like @key1 and ord_dz like @key2 and ord_dz like @key3 ) or 
 (ord_fzcode like @key1 and ord_fzcode like @key2 and ord_fzcode like @key3 ) or 
 (ord_fz like @key1 and ord_fz like @key2 and ord_fz like @key3 ) or 
 (ord_dzcode like @key1 and ord_dzcode like @key2 and ord_dzcode like @key3 ) or 
 (ord_empname like @key1 and ord_empname like @key2 and ord_empname like @key3 ) or 
 (ord_dpfzr like @key1 and ord_dpfzr like @key2 and ord_dpfzr like @key3 ) or 
 (ord_dplx like @key1 and ord_dplx like @key2 and ord_dplx like @key3 ) or 
 (ord_no like @key1 and ord_no like @key2 and ord_no like @key3 ) or 
 (ord_dpdz like @key1 and ord_dpdz like @key2 and ord_dpdz like @key3 ) or 
 (ord_dpmc like @key1 and ord_dpmc like @key2 and ord_dpmc like @key3 ) or 
 (ord_pqjlcode like @key1 and ord_pqjlcode like @key2 and ord_pqjlcode like @key3 ) or 
 (ord_dpbh like @key1 and ord_dpbh like @key2 and ord_dpbh like @key3 ) or 
 (ord_szjxs like @key1 and ord_szjxs like @key2 and ord_szjxs like @key3 ) or 
 (ord_szfgs like @key1 and ord_szfgs like @key2 and ord_szfgs like @key3 ) or 
 (ord_pqdd like @key1 and ord_pqdd like @key2 and ord_pqdd like @key3 ) or 
 (ord_pqddcode like @key1 and ord_pqddcode like @key2 and ord_pqddcode like @key3 ) or 
 (ord_pqzj like @key1 and ord_pqzj like @key2 and ord_pqzj like @key3 ) or 
 (ord_qx like @key1 and ord_qx like @key2 and ord_qx like @key3 ) or 
 (ord_lxrdh like @key1 and ord_lxrdh like @key2 and ord_lxrdh like @key3 ) or 
 (ord_pqjl like @key1 and ord_pqjl like @key2 and ord_pqjl like @key3 ) or 
 (ord_posid like @key1 and ord_posid like @key2 and ord_posid like @key3 ) or 
 (ord_jmssj like @key1 and ord_jmssj like @key2 and ord_jmssj like @key3 ) or 
 (ord_status like @key1 and ord_status like @key2 and ord_status like @key3 ) or 
 (ord_jmsmc like @key1 and ord_jmsmc like @key2 and ord_jmsmc like @key3 ) or 
 (ord_jmslxr like @key1 and ord_jmslxr like @key2 and ord_jmslxr like @key3 ) or 
 (ord_jmsdh like @key1 and ord_jmsdh like @key2 and ord_jmsdh like @key3 ) or 
 (ord_htbh like @key1 and ord_htbh like @key2 and ord_htbh like @key3 ) or 
 (ord_kdsj like @key1 and ord_kdsj like @key2 and ord_kdsj like @key3 ) ) and 
(ord_gdsj >= @date1 and ord_gdsj <= @date2 ) 
order by ord_date desc,ord_dpzt,ord_fzrcode,ord_pqzjcode,ord_gdsj desc,ord_dz,ord_fzcode,ord_fz,ord_dzcode,ord_empname,ord_dpfzr,ord_dplx,ord_no,ord_dpdz,ord_dpmc,ord_pqjlcode,ord_dpbh,ord_szjxs,ord_szfgs,ord_pqdd,ord_pqddcode,ord_pqzj,ord_qx,ord_lxrdh,ord_pqjl,ord_posid,ord_jmssj,ord_status,ord_jmsmc,ord_jmslxr,ord_jmsdh,ord_htbh,ord_kdsj desc
select count(1) resultcount  from datalinker where useruid=@useruid 
end else
begin
select count(1) cnt from order_188 a,order_188_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_dpzt like @key1 and ord_dpzt like @key2 and ord_dpzt like @key3 ) or 
 (ord_fzrcode like @key1 and ord_fzrcode like @key2 and ord_fzrcode like @key3 ) or 
 (ord_pqzjcode like @key1 and ord_pqzjcode like @key2 and ord_pqzjcode like @key3 ) or 
 (ord_dz like @key1 and ord_dz like @key2 and ord_dz like @key3 ) or 
 (ord_fzcode like @key1 and ord_fzcode like @key2 and ord_fzcode like @key3 ) or 
 (ord_fz like @key1 and ord_fz like @key2 and ord_fz like @key3 ) or 
 (ord_dzcode like @key1 and ord_dzcode like @key2 and ord_dzcode like @key3 ) or 
 (ord_empname like @key1 and ord_empname like @key2 and ord_empname like @key3 ) or 
 (ord_dpfzr like @key1 and ord_dpfzr like @key2 and ord_dpfzr like @key3 ) or 
 (ord_dplx like @key1 and ord_dplx like @key2 and ord_dplx like @key3 ) or 
 (ord_no like @key1 and ord_no like @key2 and ord_no like @key3 ) or 
 (ord_dpdz like @key1 and ord_dpdz like @key2 and ord_dpdz like @key3 ) or 
 (ord_dpmc like @key1 and ord_dpmc like @key2 and ord_dpmc like @key3 ) or 
 (ord_pqjlcode like @key1 and ord_pqjlcode like @key2 and ord_pqjlcode like @key3 ) or 
 (ord_dpbh like @key1 and ord_dpbh like @key2 and ord_dpbh like @key3 ) or 
 (ord_szjxs like @key1 and ord_szjxs like @key2 and ord_szjxs like @key3 ) or 
 (ord_szfgs like @key1 and ord_szfgs like @key2 and ord_szfgs like @key3 ) or 
 (ord_pqdd like @key1 and ord_pqdd like @key2 and ord_pqdd like @key3 ) or 
 (ord_pqddcode like @key1 and ord_pqddcode like @key2 and ord_pqddcode like @key3 ) or 
 (ord_pqzj like @key1 and ord_pqzj like @key2 and ord_pqzj like @key3 ) or 
 (ord_qx like @key1 and ord_qx like @key2 and ord_qx like @key3 ) or 
 (ord_lxrdh like @key1 and ord_lxrdh like @key2 and ord_lxrdh like @key3 ) or 
 (ord_pqjl like @key1 and ord_pqjl like @key2 and ord_pqjl like @key3 ) or 
 (ord_posid like @key1 and ord_posid like @key2 and ord_posid like @key3 ) or 
 (ord_jmssj like @key1 and ord_jmssj like @key2 and ord_jmssj like @key3 ) or 
 (ord_status like @key1 and ord_status like @key2 and ord_status like @key3 ) or 
 (ord_jmsmc like @key1 and ord_jmsmc like @key2 and ord_jmsmc like @key3 ) or 
 (ord_jmslxr like @key1 and ord_jmslxr like @key2 and ord_jmslxr like @key3 ) or 
 (ord_jmsdh like @key1 and ord_jmsdh like @key2 and ord_jmsdh like @key3 ) or 
 (ord_htbh like @key1 and ord_htbh like @key2 and ord_htbh like @key3 ) or 
 (ord_kdsj like @key1 and ord_kdsj like @key2 and ord_kdsj like @key3 ) ) and 
(ord_gdsj >= @date1 and ord_gdsj <= @date2 ) 

-- 返回所有ID
insert into @pobjs(ordid) select top(@amount) ord_id from order_188 a,order_188_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_dpzt like @key1 and ord_dpzt like @key2 and ord_dpzt like @key3 ) or 
 (ord_fzrcode like @key1 and ord_fzrcode like @key2 and ord_fzrcode like @key3 ) or 
 (ord_pqzjcode like @key1 and ord_pqzjcode like @key2 and ord_pqzjcode like @key3 ) or 
 (ord_dz like @key1 and ord_dz like @key2 and ord_dz like @key3 ) or 
 (ord_fzcode like @key1 and ord_fzcode like @key2 and ord_fzcode like @key3 ) or 
 (ord_fz like @key1 and ord_fz like @key2 and ord_fz like @key3 ) or 
 (ord_dzcode like @key1 and ord_dzcode like @key2 and ord_dzcode like @key3 ) or 
 (ord_empname like @key1 and ord_empname like @key2 and ord_empname like @key3 ) or 
 (ord_dpfzr like @key1 and ord_dpfzr like @key2 and ord_dpfzr like @key3 ) or 
 (ord_dplx like @key1 and ord_dplx like @key2 and ord_dplx like @key3 ) or 
 (ord_no like @key1 and ord_no like @key2 and ord_no like @key3 ) or 
 (ord_dpdz like @key1 and ord_dpdz like @key2 and ord_dpdz like @key3 ) or 
 (ord_dpmc like @key1 and ord_dpmc like @key2 and ord_dpmc like @key3 ) or 
 (ord_pqjlcode like @key1 and ord_pqjlcode like @key2 and ord_pqjlcode like @key3 ) or 
 (ord_dpbh like @key1 and ord_dpbh like @key2 and ord_dpbh like @key3 ) or 
 (ord_szjxs like @key1 and ord_szjxs like @key2 and ord_szjxs like @key3 ) or 
 (ord_szfgs like @key1 and ord_szfgs like @key2 and ord_szfgs like @key3 ) or 
 (ord_pqdd like @key1 and ord_pqdd like @key2 and ord_pqdd like @key3 ) or 
 (ord_pqddcode like @key1 and ord_pqddcode like @key2 and ord_pqddcode like @key3 ) or 
 (ord_pqzj like @key1 and ord_pqzj like @key2 and ord_pqzj like @key3 ) or 
 (ord_qx like @key1 and ord_qx like @key2 and ord_qx like @key3 ) or 
 (ord_lxrdh like @key1 and ord_lxrdh like @key2 and ord_lxrdh like @key3 ) or 
 (ord_pqjl like @key1 and ord_pqjl like @key2 and ord_pqjl like @key3 ) or 
 (ord_posid like @key1 and ord_posid like @key2 and ord_posid like @key3 ) or 
 (ord_jmssj like @key1 and ord_jmssj like @key2 and ord_jmssj like @key3 ) or 
 (ord_status like @key1 and ord_status like @key2 and ord_status like @key3 ) or 
 (ord_jmsmc like @key1 and ord_jmsmc like @key2 and ord_jmsmc like @key3 ) or 
 (ord_jmslxr like @key1 and ord_jmslxr like @key2 and ord_jmslxr like @key3 ) or 
 (ord_jmsdh like @key1 and ord_jmsdh like @key2 and ord_jmsdh like @key3 ) or 
 (ord_htbh like @key1 and ord_htbh like @key2 and ord_htbh like @key3 ) or 
 (ord_kdsj like @key1 and ord_kdsj like @key2 and ord_kdsj like @key3 ) ) and 
(ord_gdsj >= @date1 and ord_gdsj <= @date2 ) 
order by ord_date desc,ord_dpzt,ord_fzrcode,ord_pqzjcode,ord_gdsj desc,ord_dz,ord_fzcode,ord_fz,ord_dzcode,ord_empname,ord_dpfzr,ord_dplx,ord_no,ord_dpdz,ord_dpmc,ord_pqjlcode,ord_dpbh,ord_szjxs,ord_szfgs,ord_pqdd,ord_pqddcode,ord_pqzj,ord_qx,ord_lxrdh,ord_pqjl,ord_posid,ord_jmssj,ord_status,ord_jmsmc,ord_jmslxr,ord_jmsdh,ord_htbh,ord_kdsj desc
select ordid from @pobjs 
order by nid 
-- 返回第一页 
select top(@pagesize) a.* from order_188 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_188_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_188 a,order_188_users 
where a.ord_cmpid=@cmpid 
and a.ord_id=ordp_ordid 
and ordp_type='bizview' 
and ordp_cuid=@useruid 
and (a.ord_status=@status or @status='') 
and a.ord_finished>=2 
and (
 (ord_dpzt like @key1 and ord_dpzt like @key2 and ord_dpzt like @key3 ) or 
 (ord_fzrcode like @key1 and ord_fzrcode like @key2 and ord_fzrcode like @key3 ) or 
 (ord_pqzjcode like @key1 and ord_pqzjcode like @key2 and ord_pqzjcode like @key3 ) or 
 (ord_dz like @key1 and ord_dz like @key2 and ord_dz like @key3 ) or 
 (ord_fzcode like @key1 and ord_fzcode like @key2 and ord_fzcode like @key3 ) or 
 (ord_fz like @key1 and ord_fz like @key2 and ord_fz like @key3 ) or 
 (ord_dzcode like @key1 and ord_dzcode like @key2 and ord_dzcode like @key3 ) or 
 (ord_empname like @key1 and ord_empname like @key2 and ord_empname like @key3 ) or 
 (ord_dpfzr like @key1 and ord_dpfzr like @key2 and ord_dpfzr like @key3 ) or 
 (ord_dplx like @key1 and ord_dplx like @key2 and ord_dplx like @key3 ) or 
 (ord_no like @key1 and ord_no like @key2 and ord_no like @key3 ) or 
 (ord_dpdz like @key1 and ord_dpdz like @key2 and ord_dpdz like @key3 ) or 
 (ord_dpmc like @key1 and ord_dpmc like @key2 and ord_dpmc like @key3 ) or 
 (ord_pqjlcode like @key1 and ord_pqjlcode like @key2 and ord_pqjlcode like @key3 ) or 
 (ord_dpbh like @key1 and ord_dpbh like @key2 and ord_dpbh like @key3 ) or 
 (ord_szjxs like @key1 and ord_szjxs like @key2 and ord_szjxs like @key3 ) or 
 (ord_szfgs like @key1 and ord_szfgs like @key2 and ord_szfgs like @key3 ) or 
 (ord_pqdd like @key1 and ord_pqdd like @key2 and ord_pqdd like @key3 ) or 
 (ord_pqddcode like @key1 and ord_pqddcode like @key2 and ord_pqddcode like @key3 ) or 
 (ord_pqzj like @key1 and ord_pqzj like @key2 and ord_pqzj like @key3 ) or 
 (ord_qx like @key1 and ord_qx like @key2 and ord_qx like @key3 ) or 
 (ord_lxrdh like @key1 and ord_lxrdh like @key2 and ord_lxrdh like @key3 ) or 
 (ord_pqjl like @key1 and ord_pqjl like @key2 and ord_pqjl like @key3 ) or 
 (ord_posid like @key1 and ord_posid like @key2 and ord_posid like @key3 ) or 
 (ord_jmssj like @key1 and ord_jmssj like @key2 and ord_jmssj like @key3 ) or 
 (ord_status like @key1 and ord_status like @key2 and ord_status like @key3 ) or 
 (ord_jmsmc like @key1 and ord_jmsmc like @key2 and ord_jmsmc like @key3 ) or 
 (ord_jmslxr like @key1 and ord_jmslxr like @key2 and ord_jmslxr like @key3 ) or 
 (ord_jmsdh like @key1 and ord_jmsdh like @key2 and ord_jmsdh like @key3 ) or 
 (ord_htbh like @key1 and ord_htbh like @key2 and ord_htbh like @key3 ) or 
 (ord_kdsj like @key1 and ord_kdsj like @key2 and ord_kdsj like @key3 ) ) and 
(ord_gdsj >= @date1 and ord_gdsj <= @date2 ) 
order by ord_date desc,ord_dpzt,ord_fzrcode,ord_pqzjcode,ord_gdsj desc,ord_dz,ord_fzcode,ord_fz,ord_dzcode,ord_empname,ord_dpfzr,ord_dplx,ord_no,ord_dpdz,ord_dpmc,ord_pqjlcode,ord_dpbh,ord_szjxs,ord_szfgs,ord_pqdd,ord_pqddcode,ord_pqzj,ord_qx,ord_lxrdh,ord_pqjl,ord_posid,ord_jmssj,ord_status,ord_jmsmc,ord_jmslxr,ord_jmsdh,ord_htbh,ord_kdsj desc
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_188 a,order_188_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_dpzt like @key1 and ord_dpzt like @key2 and ord_dpzt like @key3 ) or 
 (ord_fzrcode like @key1 and ord_fzrcode like @key2 and ord_fzrcode like @key3 ) or 
 (ord_pqzjcode like @key1 and ord_pqzjcode like @key2 and ord_pqzjcode like @key3 ) or 
 (ord_dz like @key1 and ord_dz like @key2 and ord_dz like @key3 ) or 
 (ord_fzcode like @key1 and ord_fzcode like @key2 and ord_fzcode like @key3 ) or 
 (ord_fz like @key1 and ord_fz like @key2 and ord_fz like @key3 ) or 
 (ord_dzcode like @key1 and ord_dzcode like @key2 and ord_dzcode like @key3 ) or 
 (ord_empname like @key1 and ord_empname like @key2 and ord_empname like @key3 ) or 
 (ord_dpfzr like @key1 and ord_dpfzr like @key2 and ord_dpfzr like @key3 ) or 
 (ord_dplx like @key1 and ord_dplx like @key2 and ord_dplx like @key3 ) or 
 (ord_no like @key1 and ord_no like @key2 and ord_no like @key3 ) or 
 (ord_dpdz like @key1 and ord_dpdz like @key2 and ord_dpdz like @key3 ) or 
 (ord_dpmc like @key1 and ord_dpmc like @key2 and ord_dpmc like @key3 ) or 
 (ord_pqjlcode like @key1 and ord_pqjlcode like @key2 and ord_pqjlcode like @key3 ) or 
 (ord_dpbh like @key1 and ord_dpbh like @key2 and ord_dpbh like @key3 ) or 
 (ord_szjxs like @key1 and ord_szjxs like @key2 and ord_szjxs like @key3 ) or 
 (ord_szfgs like @key1 and ord_szfgs like @key2 and ord_szfgs like @key3 ) or 
 (ord_pqdd like @key1 and ord_pqdd like @key2 and ord_pqdd like @key3 ) or 
 (ord_pqddcode like @key1 and ord_pqddcode like @key2 and ord_pqddcode like @key3 ) or 
 (ord_pqzj like @key1 and ord_pqzj like @key2 and ord_pqzj like @key3 ) or 
 (ord_qx like @key1 and ord_qx like @key2 and ord_qx like @key3 ) or 
 (ord_lxrdh like @key1 and ord_lxrdh like @key2 and ord_lxrdh like @key3 ) or 
 (ord_pqjl like @key1 and ord_pqjl like @key2 and ord_pqjl like @key3 ) or 
 (ord_posid like @key1 and ord_posid like @key2 and ord_posid like @key3 ) or 
 (ord_jmssj like @key1 and ord_jmssj like @key2 and ord_jmssj like @key3 ) or 
 (ord_status like @key1 and ord_status like @key2 and ord_status like @key3 ) or 
 (ord_jmsmc like @key1 and ord_jmsmc like @key2 and ord_jmsmc like @key3 ) or 
 (ord_jmslxr like @key1 and ord_jmslxr like @key2 and ord_jmslxr like @key3 ) or 
 (ord_jmsdh like @key1 and ord_jmsdh like @key2 and ord_jmsdh like @key3 ) or 
 (ord_htbh like @key1 and ord_htbh like @key2 and ord_htbh like @key3 ) or 
 (ord_kdsj like @key1 and ord_kdsj like @key2 and ord_kdsj like @key3 ) ) and 
(ord_gdsj >= @date1 and ord_gdsj <= @date2 ) 
order by ord_date desc,ord_dpzt,ord_fzrcode,ord_pqzjcode,ord_gdsj desc,ord_dz,ord_fzcode,ord_fz,ord_dzcode,ord_empname,ord_dpfzr,ord_dplx,ord_no,ord_dpdz,ord_dpmc,ord_pqjlcode,ord_dpbh,ord_szjxs,ord_szfgs,ord_pqdd,ord_pqddcode,ord_pqzj,ord_qx,ord_lxrdh,ord_pqjl,ord_posid,ord_jmssj,ord_status,ord_jmsmc,ord_jmslxr,ord_jmsdh,ord_htbh,ord_kdsj desc
select count(1) resultcount  from datalinker where useruid=@useruid 
end else
begin
select count(1) cnt from order_188 a,order_188_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_dpzt like @key1 and ord_dpzt like @key2 and ord_dpzt like @key3 ) or 
 (ord_fzrcode like @key1 and ord_fzrcode like @key2 and ord_fzrcode like @key3 ) or 
 (ord_pqzjcode like @key1 and ord_pqzjcode like @key2 and ord_pqzjcode like @key3 ) or 
 (ord_dz like @key1 and ord_dz like @key2 and ord_dz like @key3 ) or 
 (ord_fzcode like @key1 and ord_fzcode like @key2 and ord_fzcode like @key3 ) or 
 (ord_fz like @key1 and ord_fz like @key2 and ord_fz like @key3 ) or 
 (ord_dzcode like @key1 and ord_dzcode like @key2 and ord_dzcode like @key3 ) or 
 (ord_empname like @key1 and ord_empname like @key2 and ord_empname like @key3 ) or 
 (ord_dpfzr like @key1 and ord_dpfzr like @key2 and ord_dpfzr like @key3 ) or 
 (ord_dplx like @key1 and ord_dplx like @key2 and ord_dplx like @key3 ) or 
 (ord_no like @key1 and ord_no like @key2 and ord_no like @key3 ) or 
 (ord_dpdz like @key1 and ord_dpdz like @key2 and ord_dpdz like @key3 ) or 
 (ord_dpmc like @key1 and ord_dpmc like @key2 and ord_dpmc like @key3 ) or 
 (ord_pqjlcode like @key1 and ord_pqjlcode like @key2 and ord_pqjlcode like @key3 ) or 
 (ord_dpbh like @key1 and ord_dpbh like @key2 and ord_dpbh like @key3 ) or 
 (ord_szjxs like @key1 and ord_szjxs like @key2 and ord_szjxs like @key3 ) or 
 (ord_szfgs like @key1 and ord_szfgs like @key2 and ord_szfgs like @key3 ) or 
 (ord_pqdd like @key1 and ord_pqdd like @key2 and ord_pqdd like @key3 ) or 
 (ord_pqddcode like @key1 and ord_pqddcode like @key2 and ord_pqddcode like @key3 ) or 
 (ord_pqzj like @key1 and ord_pqzj like @key2 and ord_pqzj like @key3 ) or 
 (ord_qx like @key1 and ord_qx like @key2 and ord_qx like @key3 ) or 
 (ord_lxrdh like @key1 and ord_lxrdh like @key2 and ord_lxrdh like @key3 ) or 
 (ord_pqjl like @key1 and ord_pqjl like @key2 and ord_pqjl like @key3 ) or 
 (ord_posid like @key1 and ord_posid like @key2 and ord_posid like @key3 ) or 
 (ord_jmssj like @key1 and ord_jmssj like @key2 and ord_jmssj like @key3 ) or 
 (ord_status like @key1 and ord_status like @key2 and ord_status like @key3 ) or 
 (ord_jmsmc like @key1 and ord_jmsmc like @key2 and ord_jmsmc like @key3 ) or 
 (ord_jmslxr like @key1 and ord_jmslxr like @key2 and ord_jmslxr like @key3 ) or 
 (ord_jmsdh like @key1 and ord_jmsdh like @key2 and ord_jmsdh like @key3 ) or 
 (ord_htbh like @key1 and ord_htbh like @key2 and ord_htbh like @key3 ) or 
 (ord_kdsj like @key1 and ord_kdsj like @key2 and ord_kdsj like @key3 ) ) and 
(ord_gdsj >= @date1 and ord_gdsj <= @date2 ) 

-- 返回所有ID
insert into @pobjs(ordid) select top(@amount) ord_id from order_188 a,order_188_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_dpzt like @key1 and ord_dpzt like @key2 and ord_dpzt like @key3 ) or 
 (ord_fzrcode like @key1 and ord_fzrcode like @key2 and ord_fzrcode like @key3 ) or 
 (ord_pqzjcode like @key1 and ord_pqzjcode like @key2 and ord_pqzjcode like @key3 ) or 
 (ord_dz like @key1 and ord_dz like @key2 and ord_dz like @key3 ) or 
 (ord_fzcode like @key1 and ord_fzcode like @key2 and ord_fzcode like @key3 ) or 
 (ord_fz like @key1 and ord_fz like @key2 and ord_fz like @key3 ) or 
 (ord_dzcode like @key1 and ord_dzcode like @key2 and ord_dzcode like @key3 ) or 
 (ord_empname like @key1 and ord_empname like @key2 and ord_empname like @key3 ) or 
 (ord_dpfzr like @key1 and ord_dpfzr like @key2 and ord_dpfzr like @key3 ) or 
 (ord_dplx like @key1 and ord_dplx like @key2 and ord_dplx like @key3 ) or 
 (ord_no like @key1 and ord_no like @key2 and ord_no like @key3 ) or 
 (ord_dpdz like @key1 and ord_dpdz like @key2 and ord_dpdz like @key3 ) or 
 (ord_dpmc like @key1 and ord_dpmc like @key2 and ord_dpmc like @key3 ) or 
 (ord_pqjlcode like @key1 and ord_pqjlcode like @key2 and ord_pqjlcode like @key3 ) or 
 (ord_dpbh like @key1 and ord_dpbh like @key2 and ord_dpbh like @key3 ) or 
 (ord_szjxs like @key1 and ord_szjxs like @key2 and ord_szjxs like @key3 ) or 
 (ord_szfgs like @key1 and ord_szfgs like @key2 and ord_szfgs like @key3 ) or 
 (ord_pqdd like @key1 and ord_pqdd like @key2 and ord_pqdd like @key3 ) or 
 (ord_pqddcode like @key1 and ord_pqddcode like @key2 and ord_pqddcode like @key3 ) or 
 (ord_pqzj like @key1 and ord_pqzj like @key2 and ord_pqzj like @key3 ) or 
 (ord_qx like @key1 and ord_qx like @key2 and ord_qx like @key3 ) or 
 (ord_lxrdh like @key1 and ord_lxrdh like @key2 and ord_lxrdh like @key3 ) or 
 (ord_pqjl like @key1 and ord_pqjl like @key2 and ord_pqjl like @key3 ) or 
 (ord_posid like @key1 and ord_posid like @key2 and ord_posid like @key3 ) or 
 (ord_jmssj like @key1 and ord_jmssj like @key2 and ord_jmssj like @key3 ) or 
 (ord_status like @key1 and ord_status like @key2 and ord_status like @key3 ) or 
 (ord_jmsmc like @key1 and ord_jmsmc like @key2 and ord_jmsmc like @key3 ) or 
 (ord_jmslxr like @key1 and ord_jmslxr like @key2 and ord_jmslxr like @key3 ) or 
 (ord_jmsdh like @key1 and ord_jmsdh like @key2 and ord_jmsdh like @key3 ) or 
 (ord_htbh like @key1 and ord_htbh like @key2 and ord_htbh like @key3 ) or 
 (ord_kdsj like @key1 and ord_kdsj like @key2 and ord_kdsj like @key3 ) ) and 
(ord_gdsj >= @date1 and ord_gdsj <= @date2 ) 
order by ord_date desc,ord_dpzt,ord_fzrcode,ord_pqzjcode,ord_gdsj desc,ord_dz,ord_fzcode,ord_fz,ord_dzcode,ord_empname,ord_dpfzr,ord_dplx,ord_no,ord_dpdz,ord_dpmc,ord_pqjlcode,ord_dpbh,ord_szjxs,ord_szfgs,ord_pqdd,ord_pqddcode,ord_pqzj,ord_qx,ord_lxrdh,ord_pqjl,ord_posid,ord_jmssj,ord_status,ord_jmsmc,ord_jmslxr,ord_jmsdh,ord_htbh,ord_kdsj desc
select ordid from @pobjs 
order by nid 
-- 返回第一页 
select top(@pagesize) a.* from order_188 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_188_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_188 a,order_188_users 
where a.ord_cmpid=@cmpid 
and a.ord_id=ordp_ordid 
and ordp_type='bizview' 
and ordp_cuid=@useruid 
and (a.ord_status=@status or @status='') 
and (a.ord_finished>0 and a.ord_finished<=1)
and (
 (ord_dpzt like @key1 and ord_dpzt like @key2 and ord_dpzt like @key3 ) or 
 (ord_fzrcode like @key1 and ord_fzrcode like @key2 and ord_fzrcode like @key3 ) or 
 (ord_pqzjcode like @key1 and ord_pqzjcode like @key2 and ord_pqzjcode like @key3 ) or 
 (ord_dz like @key1 and ord_dz like @key2 and ord_dz like @key3 ) or 
 (ord_fzcode like @key1 and ord_fzcode like @key2 and ord_fzcode like @key3 ) or 
 (ord_fz like @key1 and ord_fz like @key2 and ord_fz like @key3 ) or 
 (ord_dzcode like @key1 and ord_dzcode like @key2 and ord_dzcode like @key3 ) or 
 (ord_empname like @key1 and ord_empname like @key2 and ord_empname like @key3 ) or 
 (ord_dpfzr like @key1 and ord_dpfzr like @key2 and ord_dpfzr like @key3 ) or 
 (ord_dplx like @key1 and ord_dplx like @key2 and ord_dplx like @key3 ) or 
 (ord_no like @key1 and ord_no like @key2 and ord_no like @key3 ) or 
 (ord_dpdz like @key1 and ord_dpdz like @key2 and ord_dpdz like @key3 ) or 
 (ord_dpmc like @key1 and ord_dpmc like @key2 and ord_dpmc like @key3 ) or 
 (ord_pqjlcode like @key1 and ord_pqjlcode like @key2 and ord_pqjlcode like @key3 ) or 
 (ord_dpbh like @key1 and ord_dpbh like @key2 and ord_dpbh like @key3 ) or 
 (ord_szjxs like @key1 and ord_szjxs like @key2 and ord_szjxs like @key3 ) or 
 (ord_szfgs like @key1 and ord_szfgs like @key2 and ord_szfgs like @key3 ) or 
 (ord_pqdd like @key1 and ord_pqdd like @key2 and ord_pqdd like @key3 ) or 
 (ord_pqddcode like @key1 and ord_pqddcode like @key2 and ord_pqddcode like @key3 ) or 
 (ord_pqzj like @key1 and ord_pqzj like @key2 and ord_pqzj like @key3 ) or 
 (ord_qx like @key1 and ord_qx like @key2 and ord_qx like @key3 ) or 
 (ord_lxrdh like @key1 and ord_lxrdh like @key2 and ord_lxrdh like @key3 ) or 
 (ord_pqjl like @key1 and ord_pqjl like @key2 and ord_pqjl like @key3 ) or 
 (ord_posid like @key1 and ord_posid like @key2 and ord_posid like @key3 ) or 
 (ord_jmssj like @key1 and ord_jmssj like @key2 and ord_jmssj like @key3 ) or 
 (ord_status like @key1 and ord_status like @key2 and ord_status like @key3 ) or 
 (ord_jmsmc like @key1 and ord_jmsmc like @key2 and ord_jmsmc like @key3 ) or 
 (ord_jmslxr like @key1 and ord_jmslxr like @key2 and ord_jmslxr like @key3 ) or 
 (ord_jmsdh like @key1 and ord_jmsdh like @key2 and ord_jmsdh like @key3 ) or 
 (ord_htbh like @key1 and ord_htbh like @key2 and ord_htbh like @key3 ) or 
 (ord_kdsj like @key1 and ord_kdsj like @key2 and ord_kdsj like @key3 ) ) and 
(ord_gdsj >= @date1 and ord_gdsj <= @date2 ) 
order by ord_date desc,ord_dpzt,ord_fzrcode,ord_pqzjcode,ord_gdsj desc,ord_dz,ord_fzcode,ord_fz,ord_dzcode,ord_empname,ord_dpfzr,ord_dplx,ord_no,ord_dpdz,ord_dpmc,ord_pqjlcode,ord_dpbh,ord_szjxs,ord_szfgs,ord_pqdd,ord_pqddcode,ord_pqzj,ord_qx,ord_lxrdh,ord_pqjl,ord_posid,ord_jmssj,ord_status,ord_jmsmc,ord_jmslxr,ord_jmsdh,ord_htbh,ord_kdsj desc
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_188 a,order_188_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_dpzt like @key1 and ord_dpzt like @key2 and ord_dpzt like @key3 ) or 
 (ord_fzrcode like @key1 and ord_fzrcode like @key2 and ord_fzrcode like @key3 ) or 
 (ord_pqzjcode like @key1 and ord_pqzjcode like @key2 and ord_pqzjcode like @key3 ) or 
 (ord_dz like @key1 and ord_dz like @key2 and ord_dz like @key3 ) or 
 (ord_fzcode like @key1 and ord_fzcode like @key2 and ord_fzcode like @key3 ) or 
 (ord_fz like @key1 and ord_fz like @key2 and ord_fz like @key3 ) or 
 (ord_dzcode like @key1 and ord_dzcode like @key2 and ord_dzcode like @key3 ) or 
 (ord_empname like @key1 and ord_empname like @key2 and ord_empname like @key3 ) or 
 (ord_dpfzr like @key1 and ord_dpfzr like @key2 and ord_dpfzr like @key3 ) or 
 (ord_dplx like @key1 and ord_dplx like @key2 and ord_dplx like @key3 ) or 
 (ord_no like @key1 and ord_no like @key2 and ord_no like @key3 ) or 
 (ord_dpdz like @key1 and ord_dpdz like @key2 and ord_dpdz like @key3 ) or 
 (ord_dpmc like @key1 and ord_dpmc like @key2 and ord_dpmc like @key3 ) or 
 (ord_pqjlcode like @key1 and ord_pqjlcode like @key2 and ord_pqjlcode like @key3 ) or 
 (ord_dpbh like @key1 and ord_dpbh like @key2 and ord_dpbh like @key3 ) or 
 (ord_szjxs like @key1 and ord_szjxs like @key2 and ord_szjxs like @key3 ) or 
 (ord_szfgs like @key1 and ord_szfgs like @key2 and ord_szfgs like @key3 ) or 
 (ord_pqdd like @key1 and ord_pqdd like @key2 and ord_pqdd like @key3 ) or 
 (ord_pqddcode like @key1 and ord_pqddcode like @key2 and ord_pqddcode like @key3 ) or 
 (ord_pqzj like @key1 and ord_pqzj like @key2 and ord_pqzj like @key3 ) or 
 (ord_qx like @key1 and ord_qx like @key2 and ord_qx like @key3 ) or 
 (ord_lxrdh like @key1 and ord_lxrdh like @key2 and ord_lxrdh like @key3 ) or 
 (ord_pqjl like @key1 and ord_pqjl like @key2 and ord_pqjl like @key3 ) or 
 (ord_posid like @key1 and ord_posid like @key2 and ord_posid like @key3 ) or 
 (ord_jmssj like @key1 and ord_jmssj like @key2 and ord_jmssj like @key3 ) or 
 (ord_status like @key1 and ord_status like @key2 and ord_status like @key3 ) or 
 (ord_jmsmc like @key1 and ord_jmsmc like @key2 and ord_jmsmc like @key3 ) or 
 (ord_jmslxr like @key1 and ord_jmslxr like @key2 and ord_jmslxr like @key3 ) or 
 (ord_jmsdh like @key1 and ord_jmsdh like @key2 and ord_jmsdh like @key3 ) or 
 (ord_htbh like @key1 and ord_htbh like @key2 and ord_htbh like @key3 ) or 
 (ord_kdsj like @key1 and ord_kdsj like @key2 and ord_kdsj like @key3 ) ) and 
(ord_gdsj >= @date1 and ord_gdsj <= @date2 ) 
order by ord_date desc,ord_dpzt,ord_fzrcode,ord_pqzjcode,ord_gdsj desc,ord_dz,ord_fzcode,ord_fz,ord_dzcode,ord_empname,ord_dpfzr,ord_dplx,ord_no,ord_dpdz,ord_dpmc,ord_pqjlcode,ord_dpbh,ord_szjxs,ord_szfgs,ord_pqdd,ord_pqddcode,ord_pqzj,ord_qx,ord_lxrdh,ord_pqjl,ord_posid,ord_jmssj,ord_status,ord_jmsmc,ord_jmslxr,ord_jmsdh,ord_htbh,ord_kdsj desc
select count(1) resultcount  from datalinker where useruid=@useruid 
end else
begin
select count(1) cnt from order_188 a,order_188_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_dpzt like @key1 and ord_dpzt like @key2 and ord_dpzt like @key3 ) or 
 (ord_fzrcode like @key1 and ord_fzrcode like @key2 and ord_fzrcode like @key3 ) or 
 (ord_pqzjcode like @key1 and ord_pqzjcode like @key2 and ord_pqzjcode like @key3 ) or 
 (ord_dz like @key1 and ord_dz like @key2 and ord_dz like @key3 ) or 
 (ord_fzcode like @key1 and ord_fzcode like @key2 and ord_fzcode like @key3 ) or 
 (ord_fz like @key1 and ord_fz like @key2 and ord_fz like @key3 ) or 
 (ord_dzcode like @key1 and ord_dzcode like @key2 and ord_dzcode like @key3 ) or 
 (ord_empname like @key1 and ord_empname like @key2 and ord_empname like @key3 ) or 
 (ord_dpfzr like @key1 and ord_dpfzr like @key2 and ord_dpfzr like @key3 ) or 
 (ord_dplx like @key1 and ord_dplx like @key2 and ord_dplx like @key3 ) or 
 (ord_no like @key1 and ord_no like @key2 and ord_no like @key3 ) or 
 (ord_dpdz like @key1 and ord_dpdz like @key2 and ord_dpdz like @key3 ) or 
 (ord_dpmc like @key1 and ord_dpmc like @key2 and ord_dpmc like @key3 ) or 
 (ord_pqjlcode like @key1 and ord_pqjlcode like @key2 and ord_pqjlcode like @key3 ) or 
 (ord_dpbh like @key1 and ord_dpbh like @key2 and ord_dpbh like @key3 ) or 
 (ord_szjxs like @key1 and ord_szjxs like @key2 and ord_szjxs like @key3 ) or 
 (ord_szfgs like @key1 and ord_szfgs like @key2 and ord_szfgs like @key3 ) or 
 (ord_pqdd like @key1 and ord_pqdd like @key2 and ord_pqdd like @key3 ) or 
 (ord_pqddcode like @key1 and ord_pqddcode like @key2 and ord_pqddcode like @key3 ) or 
 (ord_pqzj like @key1 and ord_pqzj like @key2 and ord_pqzj like @key3 ) or 
 (ord_qx like @key1 and ord_qx like @key2 and ord_qx like @key3 ) or 
 (ord_lxrdh like @key1 and ord_lxrdh like @key2 and ord_lxrdh like @key3 ) or 
 (ord_pqjl like @key1 and ord_pqjl like @key2 and ord_pqjl like @key3 ) or 
 (ord_posid like @key1 and ord_posid like @key2 and ord_posid like @key3 ) or 
 (ord_jmssj like @key1 and ord_jmssj like @key2 and ord_jmssj like @key3 ) or 
 (ord_status like @key1 and ord_status like @key2 and ord_status like @key3 ) or 
 (ord_jmsmc like @key1 and ord_jmsmc like @key2 and ord_jmsmc like @key3 ) or 
 (ord_jmslxr like @key1 and ord_jmslxr like @key2 and ord_jmslxr like @key3 ) or 
 (ord_jmsdh like @key1 and ord_jmsdh like @key2 and ord_jmsdh like @key3 ) or 
 (ord_htbh like @key1 and ord_htbh like @key2 and ord_htbh like @key3 ) or 
 (ord_kdsj like @key1 and ord_kdsj like @key2 and ord_kdsj like @key3 ) ) and 
(ord_gdsj >= @date1 and ord_gdsj <= @date2 ) 

-- 返回所有ID
insert into @pobjs(ordid) select top(@amount) ord_id from order_188 a,order_188_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_dpzt like @key1 and ord_dpzt like @key2 and ord_dpzt like @key3 ) or 
 (ord_fzrcode like @key1 and ord_fzrcode like @key2 and ord_fzrcode like @key3 ) or 
 (ord_pqzjcode like @key1 and ord_pqzjcode like @key2 and ord_pqzjcode like @key3 ) or 
 (ord_dz like @key1 and ord_dz like @key2 and ord_dz like @key3 ) or 
 (ord_fzcode like @key1 and ord_fzcode like @key2 and ord_fzcode like @key3 ) or 
 (ord_fz like @key1 and ord_fz like @key2 and ord_fz like @key3 ) or 
 (ord_dzcode like @key1 and ord_dzcode like @key2 and ord_dzcode like @key3 ) or 
 (ord_empname like @key1 and ord_empname like @key2 and ord_empname like @key3 ) or 
 (ord_dpfzr like @key1 and ord_dpfzr like @key2 and ord_dpfzr like @key3 ) or 
 (ord_dplx like @key1 and ord_dplx like @key2 and ord_dplx like @key3 ) or 
 (ord_no like @key1 and ord_no like @key2 and ord_no like @key3 ) or 
 (ord_dpdz like @key1 and ord_dpdz like @key2 and ord_dpdz like @key3 ) or 
 (ord_dpmc like @key1 and ord_dpmc like @key2 and ord_dpmc like @key3 ) or 
 (ord_pqjlcode like @key1 and ord_pqjlcode like @key2 and ord_pqjlcode like @key3 ) or 
 (ord_dpbh like @key1 and ord_dpbh like @key2 and ord_dpbh like @key3 ) or 
 (ord_szjxs like @key1 and ord_szjxs like @key2 and ord_szjxs like @key3 ) or 
 (ord_szfgs like @key1 and ord_szfgs like @key2 and ord_szfgs like @key3 ) or 
 (ord_pqdd like @key1 and ord_pqdd like @key2 and ord_pqdd like @key3 ) or 
 (ord_pqddcode like @key1 and ord_pqddcode like @key2 and ord_pqddcode like @key3 ) or 
 (ord_pqzj like @key1 and ord_pqzj like @key2 and ord_pqzj like @key3 ) or 
 (ord_qx like @key1 and ord_qx like @key2 and ord_qx like @key3 ) or 
 (ord_lxrdh like @key1 and ord_lxrdh like @key2 and ord_lxrdh like @key3 ) or 
 (ord_pqjl like @key1 and ord_pqjl like @key2 and ord_pqjl like @key3 ) or 
 (ord_posid like @key1 and ord_posid like @key2 and ord_posid like @key3 ) or 
 (ord_jmssj like @key1 and ord_jmssj like @key2 and ord_jmssj like @key3 ) or 
 (ord_status like @key1 and ord_status like @key2 and ord_status like @key3 ) or 
 (ord_jmsmc like @key1 and ord_jmsmc like @key2 and ord_jmsmc like @key3 ) or 
 (ord_jmslxr like @key1 and ord_jmslxr like @key2 and ord_jmslxr like @key3 ) or 
 (ord_jmsdh like @key1 and ord_jmsdh like @key2 and ord_jmsdh like @key3 ) or 
 (ord_htbh like @key1 and ord_htbh like @key2 and ord_htbh like @key3 ) or 
 (ord_kdsj like @key1 and ord_kdsj like @key2 and ord_kdsj like @key3 ) ) and 
(ord_gdsj >= @date1 and ord_gdsj <= @date2 ) 
order by ord_date desc,ord_dpzt,ord_fzrcode,ord_pqzjcode,ord_gdsj desc,ord_dz,ord_fzcode,ord_fz,ord_dzcode,ord_empname,ord_dpfzr,ord_dplx,ord_no,ord_dpdz,ord_dpmc,ord_pqjlcode,ord_dpbh,ord_szjxs,ord_szfgs,ord_pqdd,ord_pqddcode,ord_pqzj,ord_qx,ord_lxrdh,ord_pqjl,ord_posid,ord_jmssj,ord_status,ord_jmsmc,ord_jmslxr,ord_jmsdh,ord_htbh,ord_kdsj desc
select ordid from @pobjs 
order by nid 
-- 返回第一页 
select top(@pagesize) a.* from order_188 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_188_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_188 a,order_188_users 
where a.ord_cmpid=@cmpid 
and a.ord_id=ordp_ordid 
and ordp_type='bizview' 
and ordp_cuid=@useruid 
and (a.ord_status=@status or @status='') 
and ord_finished=-1 
and (
 (ord_dpzt like @key1 and ord_dpzt like @key2 and ord_dpzt like @key3 ) or 
 (ord_fzrcode like @key1 and ord_fzrcode like @key2 and ord_fzrcode like @key3 ) or 
 (ord_pqzjcode like @key1 and ord_pqzjcode like @key2 and ord_pqzjcode like @key3 ) or 
 (ord_dz like @key1 and ord_dz like @key2 and ord_dz like @key3 ) or 
 (ord_fzcode like @key1 and ord_fzcode like @key2 and ord_fzcode like @key3 ) or 
 (ord_fz like @key1 and ord_fz like @key2 and ord_fz like @key3 ) or 
 (ord_dzcode like @key1 and ord_dzcode like @key2 and ord_dzcode like @key3 ) or 
 (ord_empname like @key1 and ord_empname like @key2 and ord_empname like @key3 ) or 
 (ord_dpfzr like @key1 and ord_dpfzr like @key2 and ord_dpfzr like @key3 ) or 
 (ord_dplx like @key1 and ord_dplx like @key2 and ord_dplx like @key3 ) or 
 (ord_no like @key1 and ord_no like @key2 and ord_no like @key3 ) or 
 (ord_dpdz like @key1 and ord_dpdz like @key2 and ord_dpdz like @key3 ) or 
 (ord_dpmc like @key1 and ord_dpmc like @key2 and ord_dpmc like @key3 ) or 
 (ord_pqjlcode like @key1 and ord_pqjlcode like @key2 and ord_pqjlcode like @key3 ) or 
 (ord_dpbh like @key1 and ord_dpbh like @key2 and ord_dpbh like @key3 ) or 
 (ord_szjxs like @key1 and ord_szjxs like @key2 and ord_szjxs like @key3 ) or 
 (ord_szfgs like @key1 and ord_szfgs like @key2 and ord_szfgs like @key3 ) or 
 (ord_pqdd like @key1 and ord_pqdd like @key2 and ord_pqdd like @key3 ) or 
 (ord_pqddcode like @key1 and ord_pqddcode like @key2 and ord_pqddcode like @key3 ) or 
 (ord_pqzj like @key1 and ord_pqzj like @key2 and ord_pqzj like @key3 ) or 
 (ord_qx like @key1 and ord_qx like @key2 and ord_qx like @key3 ) or 
 (ord_lxrdh like @key1 and ord_lxrdh like @key2 and ord_lxrdh like @key3 ) or 
 (ord_pqjl like @key1 and ord_pqjl like @key2 and ord_pqjl like @key3 ) or 
 (ord_posid like @key1 and ord_posid like @key2 and ord_posid like @key3 ) or 
 (ord_jmssj like @key1 and ord_jmssj like @key2 and ord_jmssj like @key3 ) or 
 (ord_status like @key1 and ord_status like @key2 and ord_status like @key3 ) or 
 (ord_jmsmc like @key1 and ord_jmsmc like @key2 and ord_jmsmc like @key3 ) or 
 (ord_jmslxr like @key1 and ord_jmslxr like @key2 and ord_jmslxr like @key3 ) or 
 (ord_jmsdh like @key1 and ord_jmsdh like @key2 and ord_jmsdh like @key3 ) or 
 (ord_htbh like @key1 and ord_htbh like @key2 and ord_htbh like @key3 ) or 
 (ord_kdsj like @key1 and ord_kdsj like @key2 and ord_kdsj like @key3 ) ) and 
(ord_gdsj >= @date1 and ord_gdsj <= @date2 ) 
order by ord_date desc,ord_dpzt,ord_fzrcode,ord_pqzjcode,ord_gdsj desc,ord_dz,ord_fzcode,ord_fz,ord_dzcode,ord_empname,ord_dpfzr,ord_dplx,ord_no,ord_dpdz,ord_dpmc,ord_pqjlcode,ord_dpbh,ord_szjxs,ord_szfgs,ord_pqdd,ord_pqddcode,ord_pqzj,ord_qx,ord_lxrdh,ord_pqjl,ord_posid,ord_jmssj,ord_status,ord_jmsmc,ord_jmslxr,ord_jmsdh,ord_htbh,ord_kdsj desc
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_188 a,order_188_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_dpzt like @key1 and ord_dpzt like @key2 and ord_dpzt like @key3 ) or 
 (ord_fzrcode like @key1 and ord_fzrcode like @key2 and ord_fzrcode like @key3 ) or 
 (ord_pqzjcode like @key1 and ord_pqzjcode like @key2 and ord_pqzjcode like @key3 ) or 
 (ord_dz like @key1 and ord_dz like @key2 and ord_dz like @key3 ) or 
 (ord_fzcode like @key1 and ord_fzcode like @key2 and ord_fzcode like @key3 ) or 
 (ord_fz like @key1 and ord_fz like @key2 and ord_fz like @key3 ) or 
 (ord_dzcode like @key1 and ord_dzcode like @key2 and ord_dzcode like @key3 ) or 
 (ord_empname like @key1 and ord_empname like @key2 and ord_empname like @key3 ) or 
 (ord_dpfzr like @key1 and ord_dpfzr like @key2 and ord_dpfzr like @key3 ) or 
 (ord_dplx like @key1 and ord_dplx like @key2 and ord_dplx like @key3 ) or 
 (ord_no like @key1 and ord_no like @key2 and ord_no like @key3 ) or 
 (ord_dpdz like @key1 and ord_dpdz like @key2 and ord_dpdz like @key3 ) or 
 (ord_dpmc like @key1 and ord_dpmc like @key2 and ord_dpmc like @key3 ) or 
 (ord_pqjlcode like @key1 and ord_pqjlcode like @key2 and ord_pqjlcode like @key3 ) or 
 (ord_dpbh like @key1 and ord_dpbh like @key2 and ord_dpbh like @key3 ) or 
 (ord_szjxs like @key1 and ord_szjxs like @key2 and ord_szjxs like @key3 ) or 
 (ord_szfgs like @key1 and ord_szfgs like @key2 and ord_szfgs like @key3 ) or 
 (ord_pqdd like @key1 and ord_pqdd like @key2 and ord_pqdd like @key3 ) or 
 (ord_pqddcode like @key1 and ord_pqddcode like @key2 and ord_pqddcode like @key3 ) or 
 (ord_pqzj like @key1 and ord_pqzj like @key2 and ord_pqzj like @key3 ) or 
 (ord_qx like @key1 and ord_qx like @key2 and ord_qx like @key3 ) or 
 (ord_lxrdh like @key1 and ord_lxrdh like @key2 and ord_lxrdh like @key3 ) or 
 (ord_pqjl like @key1 and ord_pqjl like @key2 and ord_pqjl like @key3 ) or 
 (ord_posid like @key1 and ord_posid like @key2 and ord_posid like @key3 ) or 
 (ord_jmssj like @key1 and ord_jmssj like @key2 and ord_jmssj like @key3 ) or 
 (ord_status like @key1 and ord_status like @key2 and ord_status like @key3 ) or 
 (ord_jmsmc like @key1 and ord_jmsmc like @key2 and ord_jmsmc like @key3 ) or 
 (ord_jmslxr like @key1 and ord_jmslxr like @key2 and ord_jmslxr like @key3 ) or 
 (ord_jmsdh like @key1 and ord_jmsdh like @key2 and ord_jmsdh like @key3 ) or 
 (ord_htbh like @key1 and ord_htbh like @key2 and ord_htbh like @key3 ) or 
 (ord_kdsj like @key1 and ord_kdsj like @key2 and ord_kdsj like @key3 ) ) and 
(ord_gdsj >= @date1 and ord_gdsj <= @date2 ) 
order by ord_date desc,ord_dpzt,ord_fzrcode,ord_pqzjcode,ord_gdsj desc,ord_dz,ord_fzcode,ord_fz,ord_dzcode,ord_empname,ord_dpfzr,ord_dplx,ord_no,ord_dpdz,ord_dpmc,ord_pqjlcode,ord_dpbh,ord_szjxs,ord_szfgs,ord_pqdd,ord_pqddcode,ord_pqzj,ord_qx,ord_lxrdh,ord_pqjl,ord_posid,ord_jmssj,ord_status,ord_jmsmc,ord_jmslxr,ord_jmsdh,ord_htbh,ord_kdsj desc
select count(1) resultcount  from datalinker where useruid=@useruid 
end else
begin
select count(1) cnt from order_188 a,order_188_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_dpzt like @key1 and ord_dpzt like @key2 and ord_dpzt like @key3 ) or 
 (ord_fzrcode like @key1 and ord_fzrcode like @key2 and ord_fzrcode like @key3 ) or 
 (ord_pqzjcode like @key1 and ord_pqzjcode like @key2 and ord_pqzjcode like @key3 ) or 
 (ord_dz like @key1 and ord_dz like @key2 and ord_dz like @key3 ) or 
 (ord_fzcode like @key1 and ord_fzcode like @key2 and ord_fzcode like @key3 ) or 
 (ord_fz like @key1 and ord_fz like @key2 and ord_fz like @key3 ) or 
 (ord_dzcode like @key1 and ord_dzcode like @key2 and ord_dzcode like @key3 ) or 
 (ord_empname like @key1 and ord_empname like @key2 and ord_empname like @key3 ) or 
 (ord_dpfzr like @key1 and ord_dpfzr like @key2 and ord_dpfzr like @key3 ) or 
 (ord_dplx like @key1 and ord_dplx like @key2 and ord_dplx like @key3 ) or 
 (ord_no like @key1 and ord_no like @key2 and ord_no like @key3 ) or 
 (ord_dpdz like @key1 and ord_dpdz like @key2 and ord_dpdz like @key3 ) or 
 (ord_dpmc like @key1 and ord_dpmc like @key2 and ord_dpmc like @key3 ) or 
 (ord_pqjlcode like @key1 and ord_pqjlcode like @key2 and ord_pqjlcode like @key3 ) or 
 (ord_dpbh like @key1 and ord_dpbh like @key2 and ord_dpbh like @key3 ) or 
 (ord_szjxs like @key1 and ord_szjxs like @key2 and ord_szjxs like @key3 ) or 
 (ord_szfgs like @key1 and ord_szfgs like @key2 and ord_szfgs like @key3 ) or 
 (ord_pqdd like @key1 and ord_pqdd like @key2 and ord_pqdd like @key3 ) or 
 (ord_pqddcode like @key1 and ord_pqddcode like @key2 and ord_pqddcode like @key3 ) or 
 (ord_pqzj like @key1 and ord_pqzj like @key2 and ord_pqzj like @key3 ) or 
 (ord_qx like @key1 and ord_qx like @key2 and ord_qx like @key3 ) or 
 (ord_lxrdh like @key1 and ord_lxrdh like @key2 and ord_lxrdh like @key3 ) or 
 (ord_pqjl like @key1 and ord_pqjl like @key2 and ord_pqjl like @key3 ) or 
 (ord_posid like @key1 and ord_posid like @key2 and ord_posid like @key3 ) or 
 (ord_jmssj like @key1 and ord_jmssj like @key2 and ord_jmssj like @key3 ) or 
 (ord_status like @key1 and ord_status like @key2 and ord_status like @key3 ) or 
 (ord_jmsmc like @key1 and ord_jmsmc like @key2 and ord_jmsmc like @key3 ) or 
 (ord_jmslxr like @key1 and ord_jmslxr like @key2 and ord_jmslxr like @key3 ) or 
 (ord_jmsdh like @key1 and ord_jmsdh like @key2 and ord_jmsdh like @key3 ) or 
 (ord_htbh like @key1 and ord_htbh like @key2 and ord_htbh like @key3 ) or 
 (ord_kdsj like @key1 and ord_kdsj like @key2 and ord_kdsj like @key3 ) ) and 
(ord_gdsj >= @date1 and ord_gdsj <= @date2 ) 

-- 返回所有ID
insert into @pobjs(ordid) select top(@amount) ord_id from order_188 a,order_188_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_dpzt like @key1 and ord_dpzt like @key2 and ord_dpzt like @key3 ) or 
 (ord_fzrcode like @key1 and ord_fzrcode like @key2 and ord_fzrcode like @key3 ) or 
 (ord_pqzjcode like @key1 and ord_pqzjcode like @key2 and ord_pqzjcode like @key3 ) or 
 (ord_dz like @key1 and ord_dz like @key2 and ord_dz like @key3 ) or 
 (ord_fzcode like @key1 and ord_fzcode like @key2 and ord_fzcode like @key3 ) or 
 (ord_fz like @key1 and ord_fz like @key2 and ord_fz like @key3 ) or 
 (ord_dzcode like @key1 and ord_dzcode like @key2 and ord_dzcode like @key3 ) or 
 (ord_empname like @key1 and ord_empname like @key2 and ord_empname like @key3 ) or 
 (ord_dpfzr like @key1 and ord_dpfzr like @key2 and ord_dpfzr like @key3 ) or 
 (ord_dplx like @key1 and ord_dplx like @key2 and ord_dplx like @key3 ) or 
 (ord_no like @key1 and ord_no like @key2 and ord_no like @key3 ) or 
 (ord_dpdz like @key1 and ord_dpdz like @key2 and ord_dpdz like @key3 ) or 
 (ord_dpmc like @key1 and ord_dpmc like @key2 and ord_dpmc like @key3 ) or 
 (ord_pqjlcode like @key1 and ord_pqjlcode like @key2 and ord_pqjlcode like @key3 ) or 
 (ord_dpbh like @key1 and ord_dpbh like @key2 and ord_dpbh like @key3 ) or 
 (ord_szjxs like @key1 and ord_szjxs like @key2 and ord_szjxs like @key3 ) or 
 (ord_szfgs like @key1 and ord_szfgs like @key2 and ord_szfgs like @key3 ) or 
 (ord_pqdd like @key1 and ord_pqdd like @key2 and ord_pqdd like @key3 ) or 
 (ord_pqddcode like @key1 and ord_pqddcode like @key2 and ord_pqddcode like @key3 ) or 
 (ord_pqzj like @key1 and ord_pqzj like @key2 and ord_pqzj like @key3 ) or 
 (ord_qx like @key1 and ord_qx like @key2 and ord_qx like @key3 ) or 
 (ord_lxrdh like @key1 and ord_lxrdh like @key2 and ord_lxrdh like @key3 ) or 
 (ord_pqjl like @key1 and ord_pqjl like @key2 and ord_pqjl like @key3 ) or 
 (ord_posid like @key1 and ord_posid like @key2 and ord_posid like @key3 ) or 
 (ord_jmssj like @key1 and ord_jmssj like @key2 and ord_jmssj like @key3 ) or 
 (ord_status like @key1 and ord_status like @key2 and ord_status like @key3 ) or 
 (ord_jmsmc like @key1 and ord_jmsmc like @key2 and ord_jmsmc like @key3 ) or 
 (ord_jmslxr like @key1 and ord_jmslxr like @key2 and ord_jmslxr like @key3 ) or 
 (ord_jmsdh like @key1 and ord_jmsdh like @key2 and ord_jmsdh like @key3 ) or 
 (ord_htbh like @key1 and ord_htbh like @key2 and ord_htbh like @key3 ) or 
 (ord_kdsj like @key1 and ord_kdsj like @key2 and ord_kdsj like @key3 ) ) and 
(ord_gdsj >= @date1 and ord_gdsj <= @date2 ) 
order by ord_date desc,ord_dpzt,ord_fzrcode,ord_pqzjcode,ord_gdsj desc,ord_dz,ord_fzcode,ord_fz,ord_dzcode,ord_empname,ord_dpfzr,ord_dplx,ord_no,ord_dpdz,ord_dpmc,ord_pqjlcode,ord_dpbh,ord_szjxs,ord_szfgs,ord_pqdd,ord_pqddcode,ord_pqzj,ord_qx,ord_lxrdh,ord_pqjl,ord_posid,ord_jmssj,ord_status,ord_jmsmc,ord_jmslxr,ord_jmsdh,ord_htbh,ord_kdsj desc
select ordid from @pobjs 
order by nid 
-- 返回第一页 
select top(@pagesize) a.* from order_188 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_188_users a , @pobjs 
where ordp_ordid=ordid 
and nid<=@pagesize 
and ordp_cuid=@useruid 
end 
end 
set nocount off end