2017-02-09 46 views
1

我有這個疑問如何使用內部聯接

Update ProductionDetails P Inner join 
( SELECT Distinct A.BaseCode, A.BaseScale, (A.BaseScale * B.BasePer/100) AS BaseVal, A.TreadCode, A.TreadScale, (A.TreadScale * B.TreadPer/100) as TreadVal, A.InterfaceCode, A.LipCode, A.LipScale, 
    (A.LipScale * B.HsPer/100) as LipVal, A.CenterCode, A.CenterScale, (A.CenterScale * B.CenterPer/100) AS CenterVal, A.StencilNo 
        from productionDetails A inner join 
          BlendMaster B on (A.InterfaceCode = b.Category AND A.BaseCode = B.Base AND A.TreadCode = B.Tread AND A.centerCode = B.center) 
      Where B.Status = yes 
) AS ResTable on (P.StencilNo = ResTable.StencilNo) 
     Set P.BaseValue = ResTable.BaseVal, P.TreadValue = ResTable.TreadVal , P.LipValue = ResTable.LipVal, P.CenterValue = ResTable.CenterVal 

我需要在BaseValue,TreadValue,CenterValue,LipValue字段更新ProductionDetails表中計算值(選擇寫更新查詢查詢...)AS ResTable

如果我寫命令從ResTable中選擇我得到的價值,但如果我更新它說錯誤「操作必須使用可更新的查詢」。我需要在的MS Access 2013

以下運行,這是對樣本數據

CREATE TABLE ProductionDetails(StencilNo Text, LipCode Text, LipScale Text,LipValue Number,BaseCode Text,BaseScale Number,BaseValue Number,InterfaceCode Text,CenterCode Text,CenterScale Number,CenterValue Number,TreadCode Text,TreadScale Number,TreadValue Number) 

Create Table BlendMaster (Category Text, Base Text, BasePer number , HsPer number, Center text, CenterPer number, Tread text, TreadPer number) 

Insert into ProductionDetails (StencilNo, LipCode , LipScale ,BaseCode ,BaseScale , InterfaceCode ,CenterCode , CenterScale , TreadCode ,TreadScale ) 
VALUES ('C160405234', '-', 0,'BFA10',48.44,'BF10+CEG28' , 'CEG28', 36.5, 'TRR51', 52.56) 

Insert into BlendMaster (Category, Base, BasePer ,HsPer, Center , CenterPer , Tread,TreadPer ) 
VALUES ('BF10+CEG28', 'BFA10',25, 25, 'CEG28', 15, 'TRR51', 18) 

回答

2

我想更新應該這樣

UPDATE p 
SET P.basevalue = ResTable.baseval, 
     P.treadvalue = ResTable.treadval, 
     P.lipvalue = ResTable.lipval, 
     P.centervalue = ResTable.centerval 
     from 
#productiondetails P 
     INNER JOIN (SELECT A.basecode, 
            A.basescale, 
            (A.basescale * B.baseper/100)  AS 
            BaseVal, 
            A.treadcode, 
            A.treadscale, 
            (A.treadscale * B.treadper/100) AS 
            TreadVal, 
            A.interfacecode, 
            A.lipcode, 
            A.lipscale, 
            (A.lipscale * B.hsper/100)  AS 
            LipVal, 
            A.centercode, 
            A.centerscale, 
            (A.centerscale * B.centerper/100) AS 
            CenterVal, 
            A.stencilno 
        FROM #productiondetails A 
          INNER JOIN #blendmaster B 
            ON A.interfacecode = b.category 
             AND A.basecode = B.base 
             AND A.centercode = B.center ) 
        ---WHERE B.status = 'yes' this condtiton is not present in yout 2 tables) 
     ResTable 
       ON P.stencilno = ResTable.stencilno 
+0

我試圖這樣做也它說查詢語法錯誤附近「關鍵字」 – Bala

+0

當我測試格式時,我運行另一個查詢「更新ProductionDetails P內部加入BlendMaster B上(P.InterfaceCode = B.Category和P.TreadCode = B.Tread和P.CenterCode = B.Center )設置P.BaseValue = 3.5 WHERE P.StencilNo ='C141200864''「與上面的結構相同,它執行成功, – Bala

+0

@Bala內部查詢返回任何數據可以檢查一次 – Chanukya