May 30, 2010 at 10:35 am
Sorry if I have the wrong place for this question but I'm new to these forums..
I have an update as follows which works fine in SQL server 2005
but throws a 'statement could not be prepared / ambiguous column names for each of the columns I am trying to update when run in SQL Server 2000
UPDATE [LINKEDSERVER].DATABASE.dbo.TABLE1
SET
TableNumber = T.TableNumber,
LineNumber = T.LineNumber,
.....
UnitNumber = T.UnitNumber
FROM [LINKED SERVER].DATABASE.dbo.TABLE1 AS W,
[LINKEDSERVER].DATABASE.dbo.temporaryTABLE AS
WHERE W.IdentityID = T.IdentityID
Can anyone shed any light on this as I need to get the update to work in SQL 2000?
May 30, 2010 at 10:40 am
if there are two tables, aliased W and T, i think it should look like this:
UPDATE W
SET
W.TableNumber = T.TableNumber,
W.LineNumber = T.LineNumber,
.....
UnitNumber = T.UnitNumber
FROM [LINKED SERVER].DATABASE.dbo.TABLE1 AS W,
[LINKEDSERVER].DATABASE.dbo.temporaryTABLE AS T
WHERE W.IdentityID = T.IdentityID
Lowell
May 30, 2010 at 1:36 pm
Unfortunately not - although your suggestion looks fine the error is the same:
Server: Msg 8180, Level 16, State 1, Line 1
Statement(s) could not be prepared.
Server: Msg 209, Level 16, State 1, Line 1
Ambiguous column name 'UnitNumber'. .......
Ultimately I am trying to update TABLE1 from TemporaryTABLE, both of which are on the linked server. This syntax works fine on SQL2005 and SQL2000 if you are just updating TABLE1 from a local table but as soon as you try updating from a table on the linked server itself SQL 2000 complains.
I am running the update entirely on the linked server for performance reasons and it works well in SQL2005 but fails in SQL2000. If there is a better way of doing this, perhaps using OPENQUERY I'd appreciate some pointers but the question remains : what is the right syntax to update one table from another with BOTH tables on a linked server and in SQL2000?
June 1, 2010 at 8:59 am
Try re-writing your code in ANSI style joins.
UPDATE W
SET TableNumber = T.TableNumber,
LineNumber = T.LineNumber,
.....
UnitNumber = T.UnitNumber
FROM [LINKED SERVER].DATABASE.dbo.TABLE1 AS W
INNER JOIN [LINKEDSERVER].DATABASE.dbo.temporaryTABLE AS T
ON W.IdentityID = T.IdentityID
The method you are using is deprecated and will be going away as soon as Microsoft decides to stop supporting it.
June 1, 2010 at 4:16 pm
Many thanks for the suggestion but still no luck - the same error.
Having said that I got round the problem by renaming the columns in the temporary table so that the two tables no longer had identical column names.
April 2, 2011 at 5:08 am
yes, you can solve the issue by renaming the columns in any of the table. Thanks for the hint.
Viewing 6 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply