views:

318

answers:

1

Trying to run a cross-server update:

UPDATE cmslive.CMSFintrac.dbo.lsipos
SET PostHistorySequencenNmber = (
    SELECT TransactionNumber 
    FROM Transactions 
    WHERE Transactions.TransactionDate = 
         cmslive.CMSFintrac.dbo.lsipos.TransactionDate)

Gives the error:

Server: Msg 117, Level 15, State 2, Line 5
The number name 'cmslive.CMSFintrac.dbo.lsipos' contains more than 
the maximum number of prefixes. The maximum is 3.

What gives?


Note: Rearranging the query into a less readable join form:

UPDATE cmslive.CMSFintrac.dbo.lsipos
SET PostHistorySequenceNumber = B.TransactionNumber
FROM cmslive.CMSFintrac.dbo.lsipos A
    INNER JOIN Transactions B
    ON A.TransactionDate = B.TransactionDate

does not give an error.

+1  A: 

Yes, that is just the way it is. You can't have more than three prefixes, so you have to use an aliases when you go over 3 (mainly when joining to other servers). It's been that way since Sql Server 7 (and maybe before I can't remember on 6.5).

If you want to make your code more readable when using aliases, specify a more meaningful alias which will make it a lot easier to follow.

Example:

SELECT 

production_accounting_clients.[ClientName]

FROM Production.Accounting.dbo.Clients production_accounting_clients
Kevin
Agree, aliases help SQL readability greatly
gbn
+1 if you can give an example of an of aliased form.
Ian Boyd
My select doesn't have a problem with a four-part prefix, the update does. And the `update` doesn't allow an alias. So i'm still curious to see a working syntax.
Ian Boyd