用友ERP-NC精華實用SQL腳本之:快速複製公司的權限

本文作者:草上飛
網址: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,@left4in (
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,@left4in (
select cgroupid from sm_group where pk_corp=@topkcorp
)

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章