IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[dbo].[pub_g_webservice]') AND type = 'P')
DROP PROCEDURE [dbo].[pub_g_webservice]
GO
 
CREATE  procedure [dbo].[pub_g_webservice](
@cmpid int,
@pagesize int , 
@pagecount int , 
@pageobjids varchar(8000),
@key nvarchar(50)
) 
as 
begin 
 
set nocount on  
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 svc_id,svc_cmpid,svc_name,svc_url,svc_method,svc_paramtype,svc_resulttype,svc_note,svc_language,svc_requesttype,
convert(varchar(50),svc_extsql) svc_extsql ,
svc_displayflds,svc_resultfld,svc_nextexecute,svc_cycle,svc_bizid,svc_biztype,svc_bizparams 
from  ebs_kernel..pub_webservice a, @pobjs
where svc_id=ordid
order by nid 
return 
end 

set @key = '%'+@key+'%' 
select count(1) cnt from ebs_kernel..pub_webservice  
where svc_cmpid=@cmpid and 
(
 (svc_name like @key ) or 
 (svc_url like @key) or 
 (svc_biztype like @key) or 
 (svc_note like @key) or 
 (svc_method like @key)
) 

-- 返回所有ID
insert into @pobjs(ordid) select top(@amount) svc_id from ebs_kernel..pub_webservice 
where svc_cmpid=@cmpid and 
(
 (svc_name like @key ) or 
 (svc_url like @key) or 
 (svc_biztype like @key) or 
 (svc_note like @key) or 
 (svc_method like @key)
)
order by svc_name 

select ordid from @pobjs 
order by nid 
-- 返回第一页 
select top(@pagesize) svc_id,svc_cmpid,svc_name,svc_url,svc_method,svc_paramtype,svc_resulttype,svc_note,svc_language,svc_requesttype,
convert(varchar(50),svc_extsql) svc_extsql ,
svc_displayflds,svc_resultfld,svc_nextexecute,svc_cycle,svc_bizid,svc_biztype,svc_bizparams 
from ebs_kernel..pub_webservice a,@pobjs 
where a.svc_id=ordid 
order by nid


set nocount off 

end