2013-08-20 55 views
-2
Update PSSFAAssets 

Set PSSFAAssets.ProjectID = xhh_quickscan.ProjectID, 
    PSSFAAssets.CpnyAssetNo = xhh_quickscan.Barcode, 
    PSSFAAssets.CustomDate01 = xhh_quickscan.Date1, 
    PSSFAAssets.CustomDate02 = xhh_quickscan.Date2, 
    PSSFAAssets.CustomDate03 = xhh_quickscan.Date3, 
    PSSFAAssets.CustomDate00 = xhh_quickscan.Date4, 
    PSSFAAssets.SerialNo = xhh_quickscan.Serial, 
    PSSFAAssets.Custom10Char02 = xhh_quickscan.AStatus, 
    PSSFAAssets.CustomDate04 = xhh_quickscan.Scandate 
From 
    (select * from xhh_quickscan 
    where crtdate > '8/17/2013 7:55 AM' 
    and crtdate <= '8/18/2013 2:37 PM') 

ON PSSFAAssets.AssetID = xhh_quickscan.AssetID 

拋出錯誤:「關鍵字'ON'附近語法不正確。
嘗試子「WHERE」爲「ON」;沒有運氣。從選擇錯誤Sql更新

回答

1

這是一個UPDATE正確的語法與SQL Server上JOIN

UPDATE A 
SET A.ProjectID = B.ProjectID, 
    A.CpnyAssetNo = B.Barcode, 
    A.CustomDate01 = B.Date1, 
    A.CustomDate02 = B.Date2, 
    A.CustomDate03 = B.Date3, 
    A.CustomDate00 = B.Date4, 
    A.SerialNo = B.Serial, 
    A.Custom10Char02 = B.AStatus, 
    A.CustomDate04 = B.Scandate 
FROM PSSFAAssets A 
INNER JOIN (SELECT * 
      FROM xhh_quickscan 
      WHERE crtdate > '8/17/2013 7:55 AM' 
      AND crtdate <= '8/18/2013 2:37 PM') B 
ON A.AssetID = B.AssetID 
2

爲什麼不更簡單?子查詢對我來說似乎是多餘的。

UPDATE p 
SET ProjectID  = s.ProjectID, 
    CpnyAssetNo = s.Barcode, 
    CustomDate01 = s.Date1, 
    CustomDate02 = s.Date2, 
    CustomDate03 = s.Date3, 
    CustomDate00 = s.Date4, 
    SerialNo  = s.Serial, 
    Custom10Char02 = s.AStatus, 
    CustomDate04 = s.Scandate 
FROM dbo.PSSFAAssets AS p 
INNER JOIN dbo.xhh_quickscan AS s 
ON p.AssetID = s.AssetID 
WHERE s.crtdate > '20130817 07:55' 
    AND s.crtdate <= '20130818 14:37'; 
0

這將是最好的方式來做到這一點。

Update PSSFAAssets 
Set PSSFAAssets.ProjectID = xhh_quickscan.ProjectID, 
    PSSFAAssets.CpnyAssetNo = xhh_quickscan.Barcode, 
    PSSFAAssets.CustomDate01 = xhh_quickscan.Date1, 
    PSSFAAssets.CustomDate02 = xhh_quickscan.Date2, 
    PSSFAAssets.CustomDate03 = xhh_quickscan.Date3, 
    PSSFAAssets.CustomDate00 = xhh_quickscan.Date4, 
    PSSFAAssets.SerialNo = xhh_quickscan.Serial, 
    PSSFAAssets.Custom10Char02 = xhh_quickscan.AStatus, 
    PSSFAAssets.CustomDate04 = xhh_quickscan.Scandate 
From xhh_quickscan 
where xhh_quickscan.crtdate > '8/17/2013 7:55 AM' 
    and xhh_quickscan.crtdate <= '8/18/2013 2:37 PM' 
    and PSSFAAssets.AssetID = xhh_quickscan.AssetID