马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?注册账号
×
本帖最后由 stonys 于 2023-6-1 22:17 编辑
这是记忆中第二次写脚本修改U9数据库中数据,U9数据表太多,一般都不敢动,怕出问题,这次需要修改的是一个扩展字段,没有多的数据出错担心,就进行了一翻研究。这里面也头一次用了update + innser join这个语句,也算是学习了下,下面是实例分享上!
/*
任务需求:
下游A组织与上游B组织采用了集采分收的业务,A组织请购单行中有一行备注栏,原来是私有段。
转到B组织采购时不能将私有段的数据带过去,用户已经做了好多单据,不同意删除重新做。现考虑增加公共扩展字段,
将原来的私有段的数据移到公共段中。
操作步骤:
分两步:一要在A组织中将私有字段数据移动到公共段中,二要将已经抛转到B的请购单公共段中数据更新过来。
1、将A组织请购单中行备注中的内容更新到行公共扩展字段中。
2、由于采用了集采分收的业务模式,A的请购单部分已抛转到B中,第二步将A组织中公共段中的扩展字段内容放到临时表中(表中包括行ID)
3、将临时表中的信息更新到请购单中,以行ID为标记,即当临时表中的行ID=请购单中来源ID时,更新扩展字段数据。
*/
--查询结果
select A3.[Name] as [A_Org_Name], A.[DocNo] as [A_DocNo], A4.[ItemInfo_ItemCode] as [A_PRLineList_ItemInfo_ItemCode], A4.[ItemInfo_ItemName] as [A_PRLineList_ItemInfo_ItemName], A4.[DescFlexSegments_PubDescSeg37] as [A_PRLineList_DescFlexSegments_PubDescSeg37], A5.[Memo] as [A_PRLineList_Memo], A.[BusinessDate] as [A_BusinessDate] from PR_PR as A inner join PR_PRLine as A1 on (A.[ID] = A1.[PR]) left join [Base_Organization] as A2 on (A.[Org] = A2.[ID]) left join [Base_Organization_Trl] as A3 on (A3.SysMlFlag = 'zh-CN') and (A2.[ID] = A3.[ID]) inner join [PR_PRLine] as A4 on (A.[ID] = A4.[PR]) left join [PR_PRLine_Trl] as A5 on (A5.SysMlFlag = 'zh-CN') and (A4.[ID] = A5.[ID]) where ((A.[BusinessDate] >= '2012-07-12'))
--执行第一步操作
update PR_PRLine set PR_PRLine.[DescFlexSegments_PubDescSeg37] = A1.[Memo] from PR_PRLine as A inner join [PR_PRLine_Trl] as A1 on (A1.SysMlFlag = 'zh-CN') and (A.[ID] = A1.[ID])
--执行第二步操作
create table #tb_PubDescSegTemp
(
LineID nvarchar(50),
DescPub nvarchar(100)
)
insert into #tb_PubDescSegTemp
select A.[ID] as [B_ID], A.[DescFlexSegments_PubDescSeg37] as [B_DescFlexSegments_PubDescSeg37] from PR_PRLine as A
--执行第三步操作
--select A.[DescFlexSegments_PubDescSeg37] as [B_DescFlexSegments_PubDescSeg37], A.[SrcDocInfo_SrcDocLine_EntityID] as [B_SrcDocInfo_SrcDocLine_EntityID] from PR_PRLine as A
update PR_PRLine set PR_PRLine.DescFlexSegments_PubDescSeg37=#tb_PubDescSegTemp.DescPub from #tb_PubDescSegTemp where PR_PRLine.SrcDocInfo_SrcDocLine_EntityID=#tb_PubDescSegTemp.LineID
|