Is it in anyway possible to reference a strongly typed SQL table object directly, even after it has been aliased?
For example, the following script renders a The multi-part identifier "dbo.MyTable.Col3" could not be bound
exception:
SELECT
*
FROM dbo.MyTable MT
INNER JOIN dbo.AnotherTable AT ON
MT.Col1 = AT.Col2
WHERE
dbo.MyTable.Col3 = 'Foo'
Should You Use the SQL AS Keyword with Table Aliases? The AS keyword is optional when using it with a table alias.
Standard SQL disallows references to column aliases in a WHERE clause. This restriction is imposed because when the WHERE clause is evaluated, the column value may not yet have been determined.
TABLE ALIASES are used to shorten your SQL to make it easier to read or when you are performing a self join (ie: listing the same table more than once in the FROM clause).
An alias removes ambiguity when you have more than one table because you know which table it comes from. It also prevents future table changes from breaking a query.
No, you cannot.
To quote from FROM
(Transact-SQL):
The table name cannot be used if an alias is defined.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With