用友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
网址: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
相关文章推荐
- 用友ERP-NC精华实用SQL脚本之:快速复制公司的权限
- 用友ERP-NC精华实用SQL脚本之:快速复制公司的部门
- 给用户分配新的空间和权限并导入sql脚本
- SQL Server 开发之 复制表数据的SQL脚本生成器
- [推荐](T-SQL) 得到一个给定用户使用了的权限脚本
- 快速复制数据库表中的数据SQL
- 转--- 自动跳过从库复制SQL进程错误脚本
- Web端权限管理新增实用功能:批量增加操作,简单方便快速!
- 简单实用SQL脚本
- MySQL被慢sql hang住了,用shell脚本快速清除不断增长的慢sql的办法
- 【转载】MySQL被慢sql hang住了,用shell脚本快速清除不断增长的慢sql的办法
- Oracle SQL快速复制表结构或数据
- mssqlserver 复制拷贝附件sql脚本(三)之异地服务器导出
- 用SQLPLUS脚本快速导出大量数据的脚本
- 邹建:用SQL脚本实现数据库合并复制
- MySQL被慢sql hang住了,用shell脚本快速清除不断增长的慢sql的办法
- 数据库——Oracle中快速复制表结构及sql语句select into的用法
- 简单实用SQL脚本Part9:纵向回填信息
- [推荐](T-SQL) 得到一个给定用户使用了的权限脚本
- 多个业务子系统的集中统一管理用户权限,SQL脚本批量事务运行的参考代码