2015-05-14 67 views
0

我有2個疑問是這樣的:更新一個表依賴於其他表的價值

Select F_Exhibitor,F_Stand from t_order_header where F_Exhibition='10996' 

select F_ExhibitorCode,F_Stand from T_ExhibitorLocation where F_ExhibitionCode='10996' 

我想更新T_order_header表F_stand與相應F_ExhibitorCode和F_stand名T_ExhibitorLocation

+1

[使用SQL Server從選擇更新](可能重複http://stackoverflow.com/questions/2334712/update-from-select-using -sql-server) –

+0

你的命名約定遍佈全球,並且沒有代碼格式。 SQL命令更容易閱讀爲大寫(我不叫喊)對於我來說,SQL中的下劃線不起作用,然後在你的問題中你的命名約定又改變了。也許整理一下你的代碼可能會幫助你和其他人理解你的問題。 – theWhiteFox

回答

1

希望能夠正確理解請求,更新查詢可以是類似於

UPDATE o 
SET o.F_Stand = e.F_Stand 
FROM t_order_header o INNER JOIN T_ExhibitorLocation e ON e.F_ExhibitionCode = F_Exhibition 
--optional where code 
0
UPDATE t_order_header 
SET F_STAND = A.F_STAND 
FROM 
    (SELECT F_ExhibitorCode,F_Stand 
    FROM T_ExhibitorLocation 
    WHERE F_ExhibitionCode='10996')A // What's that A ? 
WHERE A.F_ExhibitorCode=F_Exhibitor 

現在就來試試.....

+0

Msg 102,Level 15,State 1,Line 1 「A」附近的語法不正確。 Msg 102,Level 15,State 1,Line 2 'A'附近語法不正確。 –

相關問題