您的位置:首页 > 数据库

用友ERP-NC精华实用SQL脚本之:快速复制操作员的权限

2008-02-15 22:22 411 查看
本文作者:草上飞
网址:http://www.newbooks.com.cn
在用友ERP-NC系统的维护过程中,由于员工的流动,我们会经常需要将一个员工的权限复制给另外一个员工。遇到公司比较多的情况时,这个操作可以说是非常麻烦的。在此,我写了一个批处理的脚本,用于方便的复制操作员的权限。本脚本在NC3.0、sql server2000的环境上通过。现我们假设需要将员工A在广东、海南公司的所有权限复制给员工B,则我们可以用以下脚本:


declare @sourceuserid char(20)


declare @touserid char(20)


declare @nowtime char(10)


declare @left4 char(4)


set @left4='AAAA' --注意:每次运行的时候,最好修改这个代码


set @nowtime='2008-01-23 11:00:00' --TS时间,可以任意修改,原则上请改为当前时间




create table #temp(pk_corp char(4))


insert into #temp values('1001') --广东 VALUE为公司的PK值


insert into #temp values('0001') --集团


insert into #temp values('1002') --海南


--如果要复制所有公司的,可以将以上代码三行代码去掉,改为:insert into @temp select pk_corp from bd_corp


select cuserid from sm_user where user_name='员工A' --得到员工A的PK值 假设为0001AA1000000001MVXN


select cuserid from sm_user where user_name='员工B' --得到员工B的PK值 假设为0001AA1000000000445U


--分以下三个操作步骤


set @sourceuserid='0001AA1000000001MVXN' --员工A


set @touserid='0001AA1000000000445U' --员工B


--1.复制来源人关联的公司。






insert into sm_userandcorp


select 0,pk_corp,@left4+right(pk_userandcorp,16),@nowtime,@touserid from sm_userandcorp where userid=@sourceuserid


and pk_corp not in (


select pk_corp from sm_userandcorp where userid=@touserid


) and pk_corp in (select pk_corp from #temp)










--2.复制关联角色


insert into sm_user_rela


select @left4+right(crelaid,16),0,groupid,pk_corp,@nowtime,@touserid from sm_user_rela


where


groupid not in(select groupid from sm_user_rela where userid=@touserid)


and


userid=@sourceuserid and pk_corp in (select pk_corp from #temp)


--3.复制用户的权限。


insert into sm_appuserpower


select @left4+right(cpowerid,16),0,funid,pk_corp,@nowtime,@touserid from sm_appuserpower where userid=@sourceuserid


and funid+pk_corp not in(


select funid+pk_corp from sm_appuserpower where userid=@touserid


) and pk_corp in (select pk_corp from #temp)




drop table #temp



更多用友ERP的精华SQL脚本请进入www.newbooks.com.cn
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: