IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[dbo].[mps_gen_biz_nextpage]') AND type = 'P')
DROP PROCEDURE [dbo].[mps_gen_biz_nextpage]
GO
create procedure [dbo].[mps_gen_biz_nextpage](
@cmpid int,
@bizid int,
@ord2tag int 
)
as
begin
set nocount on
declare @s1 nvarchar(100) 
declare @detail varchar(100)
declare @order2 varchar(100)
declare @tbname varchar(50)
declare @dbname varchar(50)
declare @fkey   varchar(50) 
declare @ord2 varchar(10) 
set @ord2 = convert(varchar(10),@ord2tag) 

exec sys_sql_getTableNamePk @cmpid,'biz',@bizid,0,@tbname output,@fkey output ,@dbname output 
declare @ss nvarchar(MAX) 
declare @sql nvarchar(MAX) 
declare @procparam nvarchar(MAX) 
set @sql = N'
-- 生成时间:'+convert(varchar(20),getdate(),120)+N' by ebs-core  
'
if (dbo.checkprocedure(@tbname+'_'+@ord2+'_nextpage')=0) set @sql=@sql+'alter ' else set @sql=@sql+'create '
set @sql = @sql+' procedure '+@tbname+N'_'+@ord2+'_nextpage'+N'(
@objids varchar(8000)
) 
as  
begin  
set nocount on 
  declare @t table(objid bigint) 
  declare @i int, @curInd int, @strlen int, @s1 varchar(100) 
  set @curInd = 1 
  set @strlen = LEN(@objids) 
  set @s1 = '''' 
  while (@curInd <= @strlen) 
  begin 
    set @i = charindex('','', @objids, @curInd) 
    if (@i>0) 
    begin 
      set @s1 = SUBSTRING(@objids, @curInd, @i - @curInd) 
      set @curInd = @i + 1 
    end 
    else if (@curInd <= @strlen) 
    begin 
      select @s1 = SUBSTRING(@objids, @curInd, @strlen - @curInd + 1) 
      set @curInd = @strlen + 1 
    end 
    if (@s1>'''') 
    begin 
      insert into @t(objid) values(convert(bigint, @s1)) 
    end 
  end 
  select a.* from '+@dbname+@tbname+'_'+@ord2+N' a, @t 
  where ord2_id = objid  
  order by ord2_order,ord2_code,ord2_id 
set nocount off
end '
exec myprint @sql 
execute(@sql)  
-- 生成mps_sql 
set @sql = ' exec mps_sys_gen_mpssql '+CONVERT(varchar(10),@cmpid)+','''+@tbname+N'_'+@ord2+'_nextpage'',
''@objids varchar(8000)''' 
execute(@sql)
set nocount off 
end