查询未更新正确的行

时间:2013-12-02 11:25:29

标签: sql sql-server sql-server-2008

尝试使用迟到的维度数据更新事实表。见见下面的代码

UPDATE FactVehicleStock
SET 
FactVehicleStock.[TOL_BidDateTime] = B.Bid_Date_and_Time,
FactVehicleStock.[TOL_AuctionDate] = B.Date_opened_for_tender,
FactVehicleStock.[TOL_OriginalLoadDate] = B.Original_Load_date,
FactVehicleStock.[TOL_ServiceHistory] = B.Service_History,
FactVehicleStock.[TOL_ReservedPrice] = B.Reserve_price,
FactVehicleStock.[TOL_BidPrice] = B.Bid_Price,
FactVehicleStock.[TOL_OriginalReservedPrice] = B.Original_Reserve_Price,
FactVehicleStock.[TOL_NoOfTimesReloaded] = B.Number_of_times_reloaded
FROM BMR_DWH.dbo.FactVehicleStock as A 
INNER JOIN BMR_STAGE.dbo.STG_Traders_Online as B
ON  A.StockbookNumber = B.Stock_Number 
INNER JOIN BMR_DWH.[dbo].[DimDealership] as C 
ON A.DEALERSHIP_KEY IN (SELECT Distinct [DEALERSHIP_KEY] 
                        FROM BMR_DWH.[dbo].[DimDealership]  
                        INNER JOIN [BMR_STAGE].[dbo].[STG_Traders_Online] E
                        ON LTRIM(RTRIM(C.MOLNUMBER)) = LTRIM(RTRIM(E.MOL_Number))
)

1 个答案:

答案 0 :(得分:0)

尝试使用正确的UPDATE SELECT语法。

如果你查看我所做的代码,我不得不改变你的查询以进行连接。看看它是否适合你。

 UPDATE BMR_DWH.dbo.FactVehicleStock as a 
           INNER JOIN BMR_STAGE.dbo.STG_Traders_Online as B
              ON  A.StockbookNumber = B.Stock_Number 
           INNER JOIN 
             (SELECT Distinct [DEALERSHIP_KEY] 
                FROM BMR_DWH.[dbo].[DimDealership] as C 
                 INNER JOIN [BMR_STAGE].[dbo].[STG_Traders_Online] E
                   ON LTRIM(RTRIM(C.MOLNUMBER)) = LTRIM(RTRIM(E.MOL_Number)) ) D
              ON A.DEALERSHIP_KEY = D.DEALERSHIP_KEY
  SET 
       FactVehicleStock.[TOL_BidDateTime] = B.Bid_Date_and_Time,
       FactVehicleStock.[TOL_AuctionDate] = B.Date_opened_for_tender,
       FactVehicleStock.[TOL_OriginalLoadDate] = B.Original_Load_date,
       FactVehicleStock.[TOL_ServiceHistory] = B.Service_History,
       FactVehicleStock.[TOL_ReservedPrice] = B.Reserve_price,
       FactVehicleStock.[TOL_BidPrice] = B.Bid_Price,
       FactVehicleStock.[TOL_OriginalReservedPrice] = B.Original_Reserve_Price,
       FactVehicleStock.[TOL_NoOfTimesReloaded] = B.Number_of_times_reloaded