2013-05-13 79 views
0

我試圖更新表中的一組記錄與另一組記錄在同一個表中的值。當我運行此查詢,我得到錯誤:使用子查詢進行更新會出錯:「多部分標識符無法綁定。」 (Sql Server 2008)

Msg 4104, Level 16, State 1, Line 1
The multi-part identifier "t.com" could not be bound.

代碼:

update tphase 
set 
    t.com = t.com + b.com, 
    t.direct = t.direct + b.direct, 
    t.fee = t.fee + b.fee, 
    t.fringe = t.fringe + b.fringe, 
    t.fte = t.fte + b.fte, 
    t.ganda = t.ganda + b.ganda, 
    t.hours = t.hours + b.hours, 
    t.overhead = t.overhead + b.overhead, 
    t.fccmga = t.fccmga + b.fccmga, 
    t.fccmoh = t.fccmoh + b.fccmoh, 
    t.lbroh = t.lbroh + b.lbroh, 
    t.ms = t.ms + b.ms 
from 
    tphase t 
inner join 
    (select * 
    from tphase 
    where program = 'xenon' and 
      class = 'earned' and 
      df_date > '2013-05-03'   
    ) as b on t.program = b.program and 
      t.cawpid = b.cawpid and 
      t.class = b.class and 
      t.cecode = b.cecode 
where 
    t.program = 'xenon' and 
    t.class = 'earned' and 
    t.df_date = '2013-05-03' ; 
+0

你可以張貼'tphase'的表結構? – 2013-05-13 18:21:14

+0

'CREATE TABLE TPHASE \t( \t PROGRAM爲nvarchar(22), \t CAWPID INT, \t CECODE爲nvarchar(59), \t CLASS爲nvarchar(20), \t DF_DATE日期時間, \t BATCHNO INT, \t COM十進制(21,6), \t DIRECT十進制(21,6), \t FEE十進制(21,6), \t FRINGE十進制(21,6), \t FTE十進制(21,6), \t甘達公十進制(21,6), \t HOURS十進制(21,6), \t OVERHEAD十進制(21,6), \t FCCMGA十進制(21,6), \t FCCMOH十進制(21,6), \t LBROH十進制(21,6), \t MS十進制(21,6) \t)' – user2378895 2013-05-14 02:12:51

回答

0

此錯誤是告訴你,沒有在tphase表命名com列。您將需要刪除該引用,或將其更改爲正確的列名稱。

+0

但是tphase鑄造爲b不顯示錯誤b.com? – 2013-05-13 18:21:30

+1

可能沒有那麼遠,因爲它之前出錯了。 – 2013-05-13 18:22:39

+0

有一個com列 – user2378895 2013-05-13 23:09:07

3

如果你給tphase別名T,你需要引用別名更新語句,也

UPDATE t 
set 
    t.com = t.com + b.com, 
... 
+0

工作!謝謝 – user2378895 2013-05-13 23:25:01

相關問題