用友ERP-NC精华实用SQL脚本之:快速复制公司的权限
2008-02-17 09:37
323 查看
本文作者:草上飞
网址:http://www.newbooks.com.cn
本SQL用于,新建公司帐套的时候,可能该新建公司与以前存在的公司的操作员及操作员的权限均会相同,则我们可以用该脚本快速复制公司之间的权限(包括操作员、角色、及操作员角色对应的权限),具体SQL脚本为:
declare @sourcepkcorp char(4) --来源公司
declare @topkcorp char(4) --目的公司
declare @nowtime char(19) --TS时间
declare @left4='AAAA'--为了使新增数据的记录与数据库中的已存记录的主键不冲突,所以新生成的主键左边4位为'AAAA'以保证不重复。
set @souecepkcorp='1011'
set @topkcorp='1015'
set @nowtime='2008-01-21 11:50:00'
--1.复制海南的角色至北京
insert into sm_group
select replace(cgroupid,@sourcepkcorp,@left4),0,group_name,group_note,@topkcorp,@nowtime from sm_group
where group_name not in (
select group_name from sm_group where pk_corp=@topkcorp
) and pk_corp=@sourcepkcorp
--2.复制角色权限。
insert into sm_usergrouppower
select @left4+right(cpowerid,16),0,funid,replace(groupid,@sourcepkcorp,@left4),@topkcorp,@nowtime from sm_usergrouppower where groupid in (
select cgroupid from sm_group where pk_corp=@sourcepkcorp
) and dr=0 and replace(groupid,@sourcepkcorp,@left4) in (
select cgroupid from sm_group where pk_corp=@topkcorp
)
--3.将海南有的用户都关联至北京公司。
insert into sm_userandcorp
select dr,@topkcorp,@left4+RIGHT(pk_userandcorp,16),@nowtime,userid from sm_userandcorp where pk_corp=@sourcepkcorp
and userid not in(
select userid from sm_userandcorp where pk_corp=@topkcorp
)
--4.将用户关联角色。
insert into sm_user_rela
select replace(crelaid,@sourcepkcorp,@topkcorp),0,replace(groupid,@sourcepkcorp,@left4),@topkcorp,@nowtime,userid from sm_user_rela
where pk_corp=@sourcepkcorp and replace(groupid,@sourcepkcorp,@left4) in (
select cgroupid from sm_group where pk_corp=@topkcorp
)
网址:http://www.newbooks.com.cn
本SQL用于,新建公司帐套的时候,可能该新建公司与以前存在的公司的操作员及操作员的权限均会相同,则我们可以用该脚本快速复制公司之间的权限(包括操作员、角色、及操作员角色对应的权限),具体SQL脚本为:
declare @sourcepkcorp char(4) --来源公司
declare @topkcorp char(4) --目的公司
declare @nowtime char(19) --TS时间
declare @left4='AAAA'--为了使新增数据的记录与数据库中的已存记录的主键不冲突,所以新生成的主键左边4位为'AAAA'以保证不重复。
set @souecepkcorp='1011'
set @topkcorp='1015'
set @nowtime='2008-01-21 11:50:00'
--1.复制海南的角色至北京
insert into sm_group
select replace(cgroupid,@sourcepkcorp,@left4),0,group_name,group_note,@topkcorp,@nowtime from sm_group
where group_name not in (
select group_name from sm_group where pk_corp=@topkcorp
) and pk_corp=@sourcepkcorp
--2.复制角色权限。
insert into sm_usergrouppower
select @left4+right(cpowerid,16),0,funid,replace(groupid,@sourcepkcorp,@left4),@topkcorp,@nowtime from sm_usergrouppower where groupid in (
select cgroupid from sm_group where pk_corp=@sourcepkcorp
) and dr=0 and replace(groupid,@sourcepkcorp,@left4) in (
select cgroupid from sm_group where pk_corp=@topkcorp
)
--3.将海南有的用户都关联至北京公司。
insert into sm_userandcorp
select dr,@topkcorp,@left4+RIGHT(pk_userandcorp,16),@nowtime,userid from sm_userandcorp where pk_corp=@sourcepkcorp
and userid not in(
select userid from sm_userandcorp where pk_corp=@topkcorp
)
--4.将用户关联角色。
insert into sm_user_rela
select replace(crelaid,@sourcepkcorp,@topkcorp),0,replace(groupid,@sourcepkcorp,@left4),@topkcorp,@nowtime,userid from sm_user_rela
where pk_corp=@sourcepkcorp and replace(groupid,@sourcepkcorp,@left4) in (
select cgroupid from sm_group where pk_corp=@topkcorp
)
相关文章推荐
- 用友ERP-NC精华实用SQL脚本之:快速复制公司的部门
- 用友ERP-NC精华实用SQL脚本之:快速复制操作员的权限
- 简单实用SQL脚本
- 多个业务子系统的集中统一管理用户权限,SQL脚本批量事务运行的参考代码
- 简单实用SQL脚本
- 简单实用SQL脚本Part:游标模板
- MYSQL5.0 脚本测试笔记【复制表结构和数据SQL语句】
- 简单实用SQL脚本Part:查找SQL Server 自增ID值不连续记录
- 兰溪用友软件,兰溪用友财务软件,兰溪用友进销存,兰溪0A,兰溪HR,兰溪ERP,兰溪PDM,兰溪CRM,兰溪PLM,兰溪U8,兰溪U9,兰溪NC,兰溪T+,兰溪BQ,兰溪T3,兰溪T6,兰溪用友年度结
- 简单实用SQL脚本Part:查找SQL Server 自增ID值不连续记录
- [推荐](T-SQL) 得到一个给定用户使用了的权限脚本
- Oracle 生成用户及权限复制(脚本)
- sql快速复制表,导入数据到新表
- 用SqlBulkCopy快速复制记录
- 简单实用SQL脚本
- 简单实用SQL脚本
- 单实用SQL脚本Part:sql多行转为一列的合并问题
- mysql快速执行超大sql脚本方法
- 给用户分配新的空间和权限并导入sql脚本
- ubuntu下实用的三大简单实用的命令~删除 复制 移动 权限不足时在前面加上sudo