权限

ALTER PROCEDURE [dbo].[AddRoleRight]
(
    @menuinfostr VARCHAR(max),
    @role INT
)
AS
  declare @StrSeprate varchar(2)
  set @StrSeprate=','
  declare   @ch int -- as   varchar(max)     
 
  begin tran --开始执行事务
  set   @menuinfostr=@menuinfostr+@StrSeprate      
  --过滤空格和换行
  select  @menuinfostr=replace(replace(@menuinfostr,char(32),''),char(13)+char(10),'')
 DELETE  FROM  dbo.MMS_Roleright WHERE RoleId=@role;
  while(@menuinfostr<>'')     
                  begin     
                  set   @ch=left(@menuinfostr,charindex(',',@menuinfostr,1)-1)
                      
                    --print @ch;
                      INSERT INTO MMS_Roleright ( RoleId, MenuId) VALUES(@role,@ch );

 
  set   @menuinfostr=stuff(@menuinfostr,1,charindex(',',@menuinfostr,1),'')     
  --print @menuinfostr;
                  end    
                  
                  
   if @@error<>0
begin rollback tran
end
else  
begin commit tran
end   

原文地址:https://www.cnblogs.com/zhangweixin/p/3977816.html