Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I UPDATE a Linked Server table where "alias" is required, in SQL Server 2000?

In SQL Server 2005 tablename can be used to distinguish which table you're referring to:

UPDATE LinkedServer.database.user.tablename
SET val=u.val
FROM localtable u
WHERE tablename.ID=u.ID

In SQL Server 2000 this results in

Server: Msg 107, Level 16, State 2
The column prefix 'tablename' does not match with a table name or alias name used in the query.

Trying

UPDATE LinkedServer.database.user.tablename
SET val=u.val
FROM localtable u
WHERE LinkedServer.database.user.tablename.ID=u.ID

results in

Server: Msg 117, Level 15, State 2
The number name 'LinkedServer.database.user.tablename' contains more than the maximum number of prefixes. The maximum is 3.

And, of course,

UPDATE LinkedServer.database.user.tablename
SET val=u.val
FROM localtable u
WHERE ID=u.ID

results in

Server: Msg 209, Level 16, State 1
Ambiguous column name 'ID'.

(In fact searching on "The number name contains more than the maximum number of prefixes. The maximum is 3." I found the answer, but I've typed up this question and I'm going to post it! :-) )

like image 241
Mark Hurd Avatar asked Jan 23 '26 03:01

Mark Hurd


1 Answers

How about:

UPDATE ls
SET ls.val=u.val
FROM LinkedServer.database.user.tablename ls
    JOIN localtable u ON ls.ID = u.ID
like image 96
AdaTheDev Avatar answered Jan 25 '26 21:01

AdaTheDev



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!