使用链接服务器更新远程表
我想使用以下代码更新远程表,但遇到此错误:
`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
I wanna update remote table with following code but I encounter this error:
`Msg 208, Level 16, State 1, Line 12
Invalid object name 'f1'.`
code:
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
错误出在 SET 子句中。您不能在列分配中指定别名。没有必要,因为您已经告诉 SQL Server UPDATE 子句中的表
应该是什么:
注意:SQL Server 并不总是为错误提供正确的行号
编辑:使用 4 部分对象名称作为普通表
另外,您的临时表表在 JOIN 中有 3 列,但仅定义了 2 列。缺少
t_bazresiFE
。于是又会报错...The error is in the SET clause. You can't specify aliases in the column assign. There is no need because you've already told SQL Server what table in the UPDATE clause
Should be:
Note: SQL Server doesn't always give the correct line number for errors
Edit: use 4 part object names as normal tables
Also, your temp table has 3 columns in the JOIN but is only defined with 2.
t_bazresiFE
is missing. So it will error again...