2011-07-09 33 views
-1

更新遠程表,我想更新的遠程表下面的代碼,但我會遇到這樣的錯誤:使用鏈接的服務器

`Msg 208, Level 16, State 1, Line 12 
Invalid object name 'f1'.` 

代碼:

declare @temp table 
    (
     co_kargah bigint, 
     code_ostan nvarchar(10) 
    ) 
    insert into @temp 
      select co_kargah,code_ostan 
       from Tbl_ghireHadese_Temp 
       where InsUpKey=2 

       update f1 /* Error location*/ 
       set 

       f1.modate_mogharar=tbl_ghireHadese.modate_mogharar, 
       f1.t_pm_mogharar=tbl_ghireHadese.t_pm_mogharar 

    from openquery([lnkworkersystem],'select * from Bazresi_Kar.dbo.Tbl_ghireHadese') f1 
       inner join @temp temp 
       on temp.co_kargah=f1.co_kargah 
        and temp.code_ostan=f1.code_ostan 
        and temp.t_bazresiFE=f1.t_bazresiFE 
       inner join tbl_ghireHadese 
        on temp.co_kargah=tbl_ghireHadese.co_kargah 
         and temp.code_ostan=tbl_ghireHadese.code_ostan 
         and temp.t_bazresiFE=tbl_ghireHadese.t_bazresiFE 

回答

1

錯誤是SET子句。您不能在列分配中指定別名。有沒有必要,因爲你已經告訴過SQL Server的什麼表中的UPDATE子句中

應該是:

update f1 
set 
    modate_mogharar = tbl_ghireHadese.modate_mogharar, 
    t_pm_mogharar = tbl_ghireHadese.t_pm_mogharar 
from 
.... 

注:SQL Server不總是給錯誤正確的行號

編輯:使用4個部分組成的對象名稱作爲普通表

... 

FROM 
    lnkworkersystem.Bazresi_Kar.dbo.Tbl_ghireHadese 
    inner join 
    @temp temp on temp.co_kargah=f1.co_kargah 
    ... 

此外,您的臨時表已在JOIN 3列,但僅與2中定義t_bazresiFE是MI ssing。所以它會再次出錯...

+0

我想使用OpenQuery,但在你的示例代碼中,你沒有使用OpenQuery.Please舉一個例子與openQuery –

+0

我給了片段,而不是完整的示例代碼。解決它。 – gbn