其他分享
首页 > 其他分享> > 多表关联时进行关联更新

多表关联时进行关联更新

作者:互联网

现有表A(CBO_MATERIAL)、B(CBO_MATCATEGORY)、C(MARA22@LINK_ECOLOGY9),将提供表A的code(A:code,C:matnr_ext)值,来进行更新表A的关联表B的ID(ID)值,表A的code值又关联了表C的code值,表C的字段phdra关联表B的code值,此时进行更新

1.先获取根据提供的(表A的code = 表C的matnr_ext)的值,获取在表C能关联到表B和表A的值:PRDHA = 表B的code,ID为表B的ID

select DISTINCT m.MATNR_EXT, m.PRDHA, cmy.ID FROM MARA22@LINK_ECOLOGY9 m
    INNER JOIN CBO_MATCATEGORY CMY ON CMY.CODE = M.PRDHA
    where m.matnr_ext IN (
     '4000006012', 
			'4000001153', 
			'4000001151', 
			'4000000111', 
			'4000000088', 
			'4000000039', 
			'4000000026', 
			'4000000006', 
			'4000000005', 
			'4000001315'
    )

在这里插入图片描述
2.进行更新

UPDATE CBO_MATERIAL C SET (C.MATCATEGORY_ID, c.BIDMATCATEGORY_ID) = (
  SELECT ID, ID FROM(
    select DISTINCT m.MATNR_EXT, m.PRDHA, cmy.ID FROM MARA22@LINK_ECOLOGY9 m
    INNER JOIN CBO_MATCATEGORY CMY ON CMY.CODE = M.PRDHA
    where m.matnr_ext IN (
     '4000006012', 
			'4000001153', 
			'4000001151', 
			'4000000111', 
			'4000000088', 
			'4000000039', 
			'4000000026', 
			'4000000006', 
			'4000000005', 
			'4000001315'
    )
  ) k WHERE c.CODE = k. matnr_ext
)WHERE c.CODE IN (
			'4000006012', 
			'4000001153', 
			'4000001151', 
			'4000000111', 
			'4000000088', 
			'4000000039', 
			'4000000026', 
			'4000000006', 
			'4000000005', 
			'4000001315'
)

标签:matnr,多表,CBO,更新,关联,ext,code,PRDHA,ID
来源: https://blog.csdn.net/Mou_O/article/details/121827594