AlePorro
AlePorro

Reputation: 131

Multi-part identifier could not be bound with basic query

I am scratching my head with the following very basic query (part of a much more complex query), where I get an error simply for using the alias I defined for a table. I was running the query in Microsoft SQL Server Management Studio v17.5, I upgraded to v17.7 but it didn't make a difference.

Why do these three versions of the query work fine

SELECT Top(3) AddressNumber from [char_test1].[dbo].[test1_READY]
SELECT Top(3) AddressNumber from [char_test1].[dbo].[test1_READY] AS Ε
SELECT Top(3) [AddressNumber] from [char_test1].[dbo].[test1_READY] AS Ε

While these three versions

SELECT Top(3) E.[AddressNumber] from [char_test1].[dbo].[test1_READY] AS Ε
SELECT Top(3) [E].[AddressNumber] from [char_test1].[dbo].[test1_READY] AS Ε
SELECT Top(3) [E].[AddressNumber] from [char_test1].[dbo].[test1_READY] AS [Ε]

give error

The multi-part identifier "E.AddressNumber" could not be bound.

(Obviously I don't need an alias here, but as I said this is the stripped-down version of a larger query with many tables, just to replicate the error)

[ UPDATE ]

Problem solved, thanks to a remark by @Gordon-Linoff. Turns out that I had copied the second group of queries from somewhere else, and the "E" character was identical to an "E" but had a different ASCII code. I checked it with python Spyder:

ord('Ε')
Out[110]: 917
ord('E')
Out[111]: 69

Upvotes: 2

Views: 466

Answers (1)

Gordon Linoff
Gordon Linoff

Reputation: 1269923

As you have written the question, all six statements should work identically . . . assuming that AddressNumber is in [char_test1].[dbo].[test1_READY].

My guess is that you have another table in the FROM when you actually run the queries. That table contains AddressNumber.

Another (rather remote) possibility is that you have another character that is invisible around the E either in the alias definition or in the alias reference. If that is the case, then retyping the code will fix the problem.

Upvotes: 1

Related Questions