更新一个表取决于另一个表的值

时间:2015-05-14 09:48:57

标签: sql sql-server

我有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_ExhibitorLocation中使用相应的F_ExhibitorCode和F_stand名称更新T_order_header表F_stand

2 个答案:

答案 0 :(得分: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

答案 1 :(得分: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

现在尝试.....