IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[dbo].[mps_sys_calc_bizpower_data_1]') AND type = 'P')
DROP PROCEDURE [dbo].[mps_sys_calc_bizpower_data_1]
GO
 
create procedure [dbo].[mps_sys_calc_bizpower_data_1](
@cmpid int ,
@bizid int ,
@ordid bigint
) as
begin
-- 计算新建人有哪些
create table #user(pptype varchar(20),cuid int , ordid bigint) 
  
declare @cnds nvarchar(1000) 
set @cnds = 'ord_id='+CONVERT(varchar(10),@ordid) 
exec mps_gen_powerusers_data @cmpid,'biz',@bizid,@bizid,'bizaudit,bizview,bizabolish,bizdelete',@cnds 

declare @tbname varchar(50)
declare @dbname varchar(50)
declare @fkey   varchar(50) 
exec sys_sql_getTableNamePk @cmpid,'biz',@bizid,0,@tbname output,@fkey output ,@dbname output 
declare @sql nvarchar(4000) 
set @sql = '

declare @user table(ptype varchar(20),uid int) 
insert into @user(ptype,uid) 
select ordp_type , ordp_cuid from '+@dbname+@tbname+'_users  with(nolock) where ordp_ordid=@ordid 

delete #user from @user where ptype=pptype and cuid=uid 

insert into '+@dbname+@tbname+'_users(ordp_type,ordp_cuid,ordp_ordid) 
select distinct pptype,cuid,@ordid from #user 
'
  
print @sql 
exec sp_executesql @sql, N'@ordid bigint', @ordid 

drop table #user 
end