— 目的将 AM8数据库表的好友,转入到 OIOrg表,这个sql 需要在 oiorg 表环境下运行 (先在am8数据库运行同名)
— 得到用户所有分组,分组成员版本初始为 1
INSERT INTO OI_ORG_CONTACT_GROUP ( S_OWNER, G_ID, S_NAME, N_MEMBER_VER )
SELECT c.S_OWNER, c.G_GROUPID, g.S_NAME, 1
FROM [AM8].[dbo].[OI_STK_CUSTOMVIEW] c
INNER JOIN [AM8].[dbo].[OI_STK_CUSTOMGROUP] g ON g.G_GROUP = c.G_GROUPID
GROUP BY c.S_OWNER, c.G_GROUPID, g.S_NAME
ORDER BY c.S_OWNER, c.G_GROUPID
— 得到所有用户联系人,会过滤掉所在分组已经没有的数据
INSERT INTO OI_ORG_CONTACT ( S_OWNER, S_USER_LOGIN, G_GROUP_ID )
SELECT c.S_OWNER, c.S_USERLOGIN, c.G_GROUPID
FROM [AM8].[dbo].[OI_STK_CUSTOMVIEW] c
WHERE c.S_USERLOGIN <> ”
AND (G_GROUPID IN ( Select G_GROUP From [AM8].[dbo].[OI_STK_CUSTOMGROUP] )
ORG_GROUPID = ‘{00000000-0000-0000-0000-000000000000}’ )
ORDER BY c.S_OWNER, c.G_GROUPID, c.S_USERLOGIN
— 得到人员的联系人版本号
UPDATE OI_ORG_T008 SET N_C41 = b.N_VER
FROM ( SELECT S_OWNER, Max( N_VER ) AS N_VER
FROM [AM8].[dbo].[OI_STK_CUSTOMVIEW]
GROUP BY S_OWNER ) b
WHERE S_C1 = b.S_OWNER
— 人员的联系人分组版本号,有分组就置 1
UPDATE OI_ORG_T008 SET N_C42 = 1 WHERE S_C1 IN ( Select S_OWNER From OI_ORG_CONTACT_GROUP )
— 清除 AM8 数据表中的 联系人 数据
— TRUNCATE TABLE [AM8].[dbo].[OI_STK_CUSTOMVIEW]
— GO
— TRUNCATE TABLE [AM8].[dbo].[OI_STK_CUSTOMGROUP]
— GO
上一篇: BPM系统之合同管理解决方案
下一篇: 合同管理软件实施过程的要点