我有一个Fact_Actuals yable,新列“Segment_Id”。
我需要将DimsegmentMaster中的段ID插入Fact_Actuals。
链接是SegmentMaster和Source Table列。
链接与FactTable是下面的源表列的度量。
请提供更新查询,因为我的以下查询不合适。
UPDATE Application_DB.[cdw].[Fact_Actuals]
set segment_sid =
(SELECT c.SID
FROM Application_DB.[cdw].[Fact_Actuals] b
inner join Source_DB.STA.SourceTable a
ON convert(decimal(20,10),LTRIM(RTRIM(a.[K308]))) = b.NetExternalSales
and convert(decimal(20,10),LTRIM(RTRIM(a.[K203]))) = b.Quantity_CON
and convert(decimal(20,10),LTRIM(RTRIM(a.[K202]))) = b.Quantity_KG
inner join Application_DB.cdw.DimSegmentMaster c
ON RTRIM(a.[C005])=c.SegmentOriginal
)
答案 0 :(得分:1)
试试这个:
UPDATE b
set segment_sid = c.sid
FROM Application_DB.[cdw].[Fact_Actuals] b
inner join Source_DB.STA.SourceTable a
ON
convert(decimal(20,10),LTRIM(RTRIM(a.[K308])))=b.NetExternalSales
and convert(decimal(20,10),LTRIM(RTRIM(a.[K203])))=b.Quantity_CON
and convert(decimal(20,10),LTRIM(RTRIM(a.[K202])))=b.Quantity_KG
inner join Application_DB.cdw.DimSegmentMaster c
ON RTRIM(a.[C005])=c.SegmentOriginal