Sometime you may get the following error:
Server: Msg 107, Level 16, State 3, Line 1
The column prefix does not match with a table name or alias name used in the query.
The main reason for this error is using table name as prefix of a column name and that table name is not included in the from clause. Another reason is you may be assigning an alias to the table name and prefix is still the table name.
Example
SELECT [Employees].[FirstName], [Customers].[LastName] FROM [dbo].[Customers]
In the above cause I had used prefixed as customers and employees but in from clause theire is only customers.
To avoid this error, always make sure that the table name used as a prefix of a column in a query exists in the FROM clause.
SELECT [Customers].[FirstName], [Customers].[LastName] FROM [dbo].[Customers]
To illustrate the second cause of this error, the following SELECT statement will generate the error:
SELECT [Customers].[FirstName], [Customers].[LastName] FROM [dbo].[Customers] Cust
Also, to avoid the second cause of this error, once you assign an alias to a table in the FROM clause, make sure to use that alias in a column prefix and not the original table name:
SELECT [Cust].[FirstName], [Cust].[LastName] FROM [dbo].[Customers] Cust
Server: Msg 107, Level 16, State 3, Line 1
The column prefix does not match with a table name or alias name used in the query.
The main reason for this error is using table name as prefix of a column name and that table name is not included in the from clause. Another reason is you may be assigning an alias to the table name and prefix is still the table name.
Example
SELECT [Employees].[FirstName], [Customers].[LastName] FROM [dbo].[Customers]
In the above cause I had used prefixed as customers and employees but in from clause theire is only customers.
To avoid this error, always make sure that the table name used as a prefix of a column in a query exists in the FROM clause.
SELECT [Customers].[FirstName], [Customers].[LastName] FROM [dbo].[Customers]
To illustrate the second cause of this error, the following SELECT statement will generate the error:
SELECT [Customers].[FirstName], [Customers].[LastName] FROM [dbo].[Customers] Cust
Also, to avoid the second cause of this error, once you assign an alias to a table in the FROM clause, make sure to use that alias in a column prefix and not the original table name:
SELECT [Cust].[FirstName], [Cust].[LastName] FROM [dbo].[Customers] Cust
No comments:
Post a Comment