IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[dbo].[mps_forum_managepeople]') AND type = 'P')
DROP PROCEDURE [dbo].[mps_forum_managepeople]
GO
create proc [dbo].[mps_forum_managepeople]
@cmpid int ,
@type varchar(100),
@bizid int,
@objid int,
@cuid int,
@usertype int,
@fmid int
as
begin
set nocount on
declare @str nvarchar(1000)
declare @tbname nvarchar(50)
declare @dbname nvarchar(50)
declare @fkey   nvarchar(50) 
declare @createcuid int
declare @createdpid int
exec sys_sql_getTableNamePk @cmpid,'biz',@bizid,0,@tbname output,@fkey output ,@dbname output 
set @str = 'select @ccuid= ord_createcuid, @cdpid = ord_createdpid from ' 
+@dbname+@tbname+ ' where ord_id='+convert(varchar(50),@objid)
--查询出创建人的cuid与dpid
exec sp_executesql @str,N'@ccuid int output,@cdpid int output',@createcuid output,@createdpid output
--创建临时表，将管理人员的cuid插入
declare @managep table(nid int identity(1,1),cuid int)
insert into @managep(cuid) select dp_mcuid1 from mps_depart where dp_id = @createdpid
insert into @managep(cuid) select dp_mcuid2 from mps_depart where dp_id = @createdpid
insert into @managep(cuid) select dp_mcuid3 from mps_depart where dp_id = @createdpid
insert into @managep(cuid) select dp_mcuid4 from mps_depart where dp_id = @createdpid
insert into @managep(cuid) select dp_mcuid5 from mps_depart where dp_id = @createdpid
insert into @managep(cuid) select dp_mcuid6 from mps_depart where dp_id = @createdpid
insert into @managep(cuid) select dp_mcuid7 from mps_depart where dp_id = @createdpid
insert into @managep(cuid) select dp_mcuid8 from mps_depart where dp_id = @createdpid
insert into @managep(cuid) select dp_mcuid9 from mps_depart where dp_id = @createdpid
insert into @managep(cuid) select dp_mcuid10 from mps_depart where dp_id = @createdpid
--查询创建人是不是管理人员,与评论人
declare @csite int
declare @fsite int
select @csite = nid from @managep where cuid = @createcuid
set @csite = ISNULL(@csite,0)
select @fsite = nid from @managep where cuid = @cuid
set @fsite = ISNULL(@csite,0)
if(@fsite>@csite) update mps_forum set fm_manage = 0 where fm_id = @fmid
else update mps_forum set fm_manage = 1 where fm_id = @fmid

set nocount off
end