Sql ошибка could not be bound

I continually get these errors when I try to update tables based on another table. I end up rewriting the query, change the order of joins, change some groupings and then it eventually works, but I just don’t quite get it.

What is a ‘multi-part identifier’?
When is a ‘multi-part identifier’ not able to be bound?
What is it being bound to anyway?
In what cases will this error occur?
What are the best ways to prevent it?

The specific error from SQL Server 2005 is:

The multi-part identifier «…» could not be bound.

Here is an example:

SELECT * FROM [MainDB].[dbo].[Company] 
WHERE [MainDB].[dbo].[Company].[CompanyName] = 'StackOverflow'

The actual error:

Msg 4104, Level 16, State 1, Line 2 The multi-part identifier
«MainDB.dbo.Company.CompanyName» could not be bound.

asked Oct 15, 2008 at 21:21

Even Mien's user avatar

Even MienEven Mien

44k43 gold badges115 silver badges119 bronze badges

A multipart identifier is any description of a field or table that contains multiple parts — for instance MyTable.SomeRow — if it can’t be bound that means there’s something wrong with it — either you’ve got a simple typo, or a confusion between table and column. It can also be caused by using reserved words in your table or field names and not surrounding them with [].
It can also be caused by not including all of the required columns in the target table.

Something like redgate sql prompt is brilliant for avoiding having to manually type these (it even auto-completes joins based on foreign keys), but isn’t free. SQL server 2008 supports intellisense out of the box, although it isn’t quite as complete as the redgate version.

Sha's user avatar

answered Oct 15, 2008 at 21:48

Whisk's user avatar

WhiskWhisk

3,2872 gold badges29 silver badges30 bronze badges

2

Actually sometimes when you are updating one table from another table’s data, I think one of the common issues that cause this error, is when you use your table abbreviations incorrectly or when they are not needed. The correct statement is below:

Update Table1
Set SomeField = t2.SomeFieldValue 
From Table1 t1 
Inner Join Table2 as t2
    On t1.ID = t2.ID

Notice that SomeField column from Table1 doesn’t have the t1 qualifier as t1.SomeField but is just SomeField.

If one tries to update it by specifying t1.SomeField the statement will return the multi-part error that you have noticed.

ΩmegaMan's user avatar

ΩmegaMan

29.1k10 gold badges99 silver badges121 bronze badges

answered Jun 20, 2011 at 15:58

amadelle's user avatar

amadelleamadelle

7515 silver badges2 bronze badges

4

It’s probably a typo. Look for the places in your code where you call [schema].[TableName] (basically anywhere you reference a field) and make sure everything is spelled correctly.

Personally, I try to avoid this by using aliases for all my tables. It helps tremendously when you can shorten a long table name to an acronym of it’s description (i.e. WorkOrderParts -> WOP), and also makes your query more readable.

Edit: As an added bonus, you’ll save TONS of keystrokes when all you have to type is a three or four-letter alias vs. the schema, table, and field names all together.

answered Oct 15, 2008 at 21:57

Lieutenant Frost's user avatar

Binding = your textual representation of a specific column gets mapped to a physical column in some table, in some database, on some server.

Multipart identifier could be: MyDatabase.dbo.MyTable. If you get any of these identifiers wrong, then you have a multipart identifier that cannot be mapped.

The best way to avoid it is to write the query right the first time, or use a plugin for management studio that provides intellisense and thus help you out by avoiding typos.

answered Oct 15, 2008 at 21:29

Mark S. Rasmussen's user avatar

0

I found that I get these a lot when I try to abbreviate, such as:

Table1 t1, Table2 t2 
where t1.ID = t2.ID

Changing it to:

Table1, Table2 
where Table1.ID = Table2.ID

Makes the query work and not throw the error.

ElderMael's user avatar

ElderMael

7,0005 gold badges34 silver badges53 bronze badges

answered May 26, 2011 at 17:59

jo-mso's user avatar

jo-msojo-mso

591 silver badge1 bronze badge

0

You probably have a typo. For instance, if you have a table named Customer in a database named Sales, you could refer to it as Sales..Customer (although it is better to refer to it including the owner name (dbo is the default owner) like Sales.dbo.Customer.

If you typed Sales…Customer, you might have gotten the message you got.

answered Oct 15, 2008 at 21:51

HLGEM's user avatar

HLGEMHLGEM

94.3k15 gold badges112 silver badges186 bronze badges

If you are sure that it is not a typo spelling-wise, perhaps it is a typo case-wise.

What collation are you using? Check it.

answered Oct 15, 2008 at 22:02

Pittsburgh DBA's user avatar

Pittsburgh DBAPittsburgh DBA

6,6422 gold badges39 silver badges68 bronze badges

When updating tables make sure you do not reference the field your updating via the alias.

I just had the error with the following code

update [page] 
set p.pagestatusid = 1
from [page] p
join seed s on s.seedid = p.seedid
where s.providercode = 'agd'
and p.pagestatusid = 0

I had to remove the alias reference in the set statement so it reads like this

update [page] 
set pagestatusid = 1
from [page] p
join seed s on s.seedid = p.seedid
where s.providercode = 'agd'
and p.pagestatusid = 0

answered Jun 20, 2012 at 0:48

Upio's user avatar

Adding table alias in front Set field causes this problem in my case.

Right

Update Table1
Set SomeField = t2.SomeFieldValue 
From Table1 t1 
Inner Join Table2 as t2
    On t1.ID = t2.ID

Wrong

Update Table1
Set t1.SomeField = t2.SomeFieldValue 
From Table1 t1 
Inner Join Table2 as t2
    On t1.ID = t2.ID

Ramil Aliyev 007's user avatar

answered Nov 22, 2018 at 22:56

Malhaar Punjabi's user avatar

I had this issue and it turned out to be an incorrect table alias. Correcting this resolved the issue.

answered Dec 15, 2011 at 14:35

Matthew Setter's user avatar

Matthew SetterMatthew Setter

2,3571 gold badge19 silver badges17 bronze badges

Mine was putting the schema on the table Alias by mistake:

SELECT * FROM schema.CustomerOrders co
WHERE schema.co.ID = 1  -- oops!

answered Feb 15, 2013 at 20:14

unnknown's user avatar

unnknownunnknown

1,6852 gold badges19 silver badges37 bronze badges

I had P.PayeeName AS 'Payer' --,
and the two comment lines threw this error

answered Jun 26, 2017 at 17:19

Andrew Day's user avatar

Andrew DayAndrew Day

56310 silver badges23 bronze badges

I actually forgot to join the table to the others that’s why i got the error

Supposed to be this way:

  CREATE VIEW reserved_passangers AS
  SELECT dbo.Passenger.PassName, dbo.Passenger.Address1, dbo.Passenger.Phone
  FROM dbo.Passenger, dbo.Reservation, dbo.Flight
  WHERE (dbo.Passenger.PassNum = dbo.Reservation.PassNum) and
  (dbo.Reservation.Flightdate = 'January 15 2004' and Flight.FlightNum =562)

And not this way:

  CREATE VIEW reserved_passangers AS
  SELECT dbo.Passenger.PassName, dbo.Passenger.Address1, dbo.Passenger.Phone
  FROM dbo.Passenger, dbo.Reservation
  WHERE (dbo.Passenger.PassNum = dbo.Reservation.PassNum) and
  (dbo.Reservation.Flightdate = 'January 15 2004' and Flight.FlightNum = 562)

answered Sep 4, 2017 at 23:17

MT_Shikomba's user avatar

Error Code

FROM                
    dbo.Category C LEFT OUTER JOIN           
    dbo.SubCategory SC ON C.categoryID = SC.CategoryID AND C.IsActive = 'True' LEFT OUTER JOIN          
    dbo.Module M ON SC.subCategoryID = M.subCategoryID AND SC.IsActive = 'True' LEFT OUTER JOIN          
    dbo.SubModule SM ON M.ModuleID = SM.ModuleID AND M.IsActive = 'True' AND SM.IsActive = 'True' LEFT OUTER JOIN 
    dbo.trainer ON dbo.trainer.TopicID =dbo.SubModule.subModuleID 

Solution Code

 FROM                
    dbo.Category C LEFT OUTER JOIN           
    dbo.SubCategory SC ON C.categoryID = SC.CategoryID AND C.IsActive = 'True' LEFT OUTER JOIN          
    dbo.Module M ON SC.subCategoryID = M.subCategoryID AND SC.IsActive = 'True' LEFT OUTER JOIN          
    dbo.SubModule SM ON M.ModuleID = SM.ModuleID AND M.IsActive = 'True' AND SM.IsActive = 'True' LEFT OUTER JOIN 
    dbo.trainer ON dbo.trainer.TopicID = SM.subModuleID 

as you can see, in error code, dbo.SubModule is already defined as SM, but I am using dbo.SubModule in next line, hence there was an error.
use declared name instead of actual name. Problem solved.

answered Jan 17, 2018 at 6:33

Onkar Vidhate's user avatar

My best advise when having the error is to use [] braquets to sorround table names, the abbreviation of tables causes sometimes errors, (sometime table abbreviations just work fine…weird)

answered Mar 9, 2018 at 19:40

ramnz's user avatar

ramnzramnz

6311 gold badge6 silver badges24 bronze badges

I was getting this error and just could not see where the problem was. I double checked all of my aliases and syntax and nothing looked out of place. The query was similar to ones I write all the time.

I decided to just re-write the query (I originally had copied it from a report .rdl file) below, over again, and it ran fine. Looking at the queries now, they look the same to me, but my re-written one works.

Just wanted to say that it might be worth a shot if nothing else works.

answered Feb 5, 2019 at 14:52

clamum's user avatar

clamumclamum

1,22710 silver badges17 bronze badges

When you type the FROM table those errors will disappear.
Type FROM below what your typing then Intellisense will work and multi-part identifier will work.

I faced this problem and solved it but there is a difference between your and mine code. In spite of I think you can understand what is «the multi-part identifier could not be bound»

When I used this code

 select * from tbTest where email = sakira@gmail.com

I faced Multi-part identifier problem

but when I use single quotation for email address It solved

 select * from tbTest where email = 'sakira@gmail.com'

answered Feb 11, 2020 at 5:34

Neloy Sarothi's user avatar

I had exactly the same issue, and similar to your coding I had missed out the FROM field, once it is added, the query knows what table to read the data from

answered Jun 9, 2021 at 9:19

TheRealJenius's user avatar

Mine worked after removing square brackets in a SUBSTRING method. I changed from

SUBSTRING([dbo.table].[column],15,2)

to

SUBSTRING(dbo.table.column,15,2)

answered Jul 7, 2021 at 19:46

abovetempo's user avatar

abovetempoabovetempo

1402 silver badges8 bronze badges

CTRL+SHIFT+R (refreshing the Intellisense) took care of it for me.

answered Jun 21, 2022 at 14:36

John's user avatar

JohnJohn

3135 silver badges9 bronze badges

I was using an alias but that alias I was not using in select

It is important to use an alias when data is coming from another database and use that alias with your select statement with fields

Example
Database_Name.dbo.Table_Name as Alias_Name with(NOLOCK)
ON
Join Condition

in Select Statement Alias_Name.Columns_Name

answered Apr 28 at 7:58

Mahipal Thakur's user avatar

There are cases where a SQL Server database developer might get an error message similar to: “The multi part identifier could not be bound“. This happens because of the way the database developer handles table scopes within the query. Read the article below, in order to better understand this error, and see how easy is to resolve it via a simple example.

Reproducing the “Multi Part Identifier Could not be Bound” Error Message

Let’s see below, a relevant example that reproduces the above error message.

Consider two tables; table Employee and table Address.

Employee table:

CREATE TABLE [dbo].[Employee](
[id] [int] NOT NULL,
[name] [varchar](50) NULL,
[age] [int] NULL
) ON [PRIMARY]

Address table

CREATE TABLE [dbo].[address](
[empid] [int] NOT NULL,
[street] [varchar](50) NULL,
[city] [varchar](50) NULL,
[country] [varchar](50) NULL
) ON [PRIMARY]

Let’s say we want to write a query returning all the employees and their country of residence sorted by the latter alphabetically.

A suggested query would be the following:

SELECT emp.name AS EmployeeName ,
 addr.country AS EmployeeCountry
FROM [Employee] emp
 INNER JOIN [Address] addr ON emp.id = addr.empID
ORDER BY addr.country ASC;

Indeed, the above query works fine.

Though if someone tried to get the employees’ country using a subquery like this:

SELECT   emp.name AS EmployeeName ,
         (   SELECT addr.country
             FROM   [Address] addr
             WHERE  addr.empID = emp.id
         ) AS EmployeeCountry
FROM     [Employee] emp
ORDER BY addr.country ASC;
GO

… then he/she would end up with the following error:

The multi-part identifier “addr.country” could not be bound.


Learn more tips like this! Enroll to our Online Course!

Check our online course titled “Essential SQL Server Development Tips for SQL Developers” (special limited-time discount included in link).

Sharpen your SQL Server database programming skills via a large set of tips on T-SQL and database development techniques. The course, among other, features over than 30 live demonstrations!

Essential SQL Server Development Tips for SQL Developers - Online Course

(Lifetime Access/ Live Demos / Downloadable Resources and more!)

Enroll from $12.99


Explaining and Resolving the Error

The problem in the above T-SQL Statement is that even though we used “addr” as a table alias in the subquery, we are not syntactically allowed to use it outside the scope of the subquery which, in this example, is in the order by clause. Though the opposite is possible, that is to reference a table/alias of an outer query within an internal query (subquery). That is why in our subquery we are able to reference the emp.id table/column.

For eliminating the above error and keep on using the subquery, the correct code for this case would be:

SELECT   emp.name AS EmployeeName ,
         (   SELECT addr.country
             FROM   [Address] addr
             WHERE  addr.empID = emp.id
         ) AS EmployeeCountry
FROM     [Employee] emp
ORDER BY EmployeeCountry;
GO

Analysis and Discussion

Even though in this example the problem was obvious, in many cases where we develop some really large and complex queries along with subqueries, we might end up consuming valuable time for resolving such issues 🙂

To this end we should always be careful when using subqueries in our T-SQL statements and always keep in mind that subqueries can only provide their results to their outer queries and not references to the subqueries’ tables.

A future post will thoroughly explain the usage of subqueries in SQL Server.

Watch video: The Multi Part Identifier Could not be Bound – How to Resolve in SQL Server

Featured Online Courses:

  • SQL Server 2022: What’s New – New and Enhanced Features [New]
  • Data Management for Beginners – Main Principles
  • Introduction to Azure Database for MySQL
  • Working with Python on Windows and SQL Server Databases
  • Boost SQL Server Database Performance with In-Memory OLTP
  • Introduction to Azure SQL Database for Beginners
  • Essential SQL Server Administration Tips
  • SQL Server Fundamentals – SQL Database for Beginners
  • Essential SQL Server Development Tips for SQL Developers
  • Introduction to Computer Programming for Beginners
  • .NET Programming for Beginners – Windows Forms with C#
  • SQL Server 2019: What’s New – New and Enhanced Features
  • Entity Framework: Getting Started – Complete Beginners Guide
  • A Guide on How to Start and Monetize a Successful Blog
  • Data Management for Beginners – Main Principles

Check some other related error messages and ways to resolve them:

  • Error converting data type varchar to float
  • Operating System Error 170 (Requested Resource is in use)
  • Installing SQL Server 2016 on Windows Server 2012 R2: Rule KB2919355 failed
  • A connection was successfully established with the server, but then an error occurred during the login process.
  • There is insufficient system memory in resource pool ‘internal’ to run this query.
  • Argument data type ntext is invalid for argument …
  • Could not load file or assembly ‘Microsoft.SqlServer.Smo, Version=10.0.0.0, …
  • Fix: VS Shell Installation has Failed with Exit Code 1638
  • The OLE DB provider “Microsoft.ACE.OLEDB.12.0” has not been registered – How to Resolve it
  • Introduction to Azure Database for MySQL (Course Preview)
  • SQL Server replication requires the actual server name to make a connection to the server – How to Resolve it
  • Issue Adding Node to a SQL Server Failover Cluster – Greyed Out Service Account – How to Resolve
  • Resolve SQL Server CTE Error – Incorrect syntax near ‘)’.
  • SQL Server is Terminating Because of Fatal Exception 80000003 – How to Troubleshoot
  • … more SQL Server troubleshooting articles

Subscribe to our newsletter and stay up to date!

Check out our latest software releases!

Check our eBooks!

Rate this article: 1 Star2 Stars3 Stars4 Stars5 Stars (8 votes, average: 5.00 out of 5)

Loading…

Reference: SQLNetHub.com (https://www.sqlnethub.com)

© SQLNetHub


The Multi Part Identifier Could not be Bound

Click to Tweet

Artemakis Artemiou

Artemakis Artemiou is a Senior SQL Server Architect, Author, a 9 Times Microsoft Data Platform MVP (2009-2018). He has over 20 years of experience in the IT industry in various roles. Artemakis is the founder of SQLNetHub and {essentialDevTips.com}. Artemakis is the creator of the well-known software tools Snippets Generator and DBA Security Advisor. Also, he is the author of many eBooks on SQL Server. Artemakis currently serves as the President of the Cyprus .NET User Group (CDNUG) and the International .NET Association Country Leader for Cyprus (INETA). Moreover, Artemakis teaches on Udemy, you can check his courses here.

Views: 13,648

If you get an error telling you that the “The multi-part identifier could not be bound.”, it usually means that you’re prefixing one or more columns with either a table that isn’t included in your query, or an alias that you haven’t actually assigned to a table.

Fortunately, the error message shows you which multi-part identifier is causing the problem.

Example

Here’s an example to demonstrate how to get the error.

SELECT * FROM Cats
INNER JOIN Dogs d
ON c.CatName = d.DogName;

Result:

Msg 4104, Level 16, State 1, Line 3
The multi-part identifier "c.CatName" could not be bound.

In this example, I forget to include an alias for the Cats table.

The error will also occur if you try to reference the table name after you’ve already provided an alias.

Like this:

SELECT * FROM Cats c
INNER JOIN Dogs d
ON Cats.CatName = d.DogName;

Result:

Msg 4104, Level 16, State 1, Line 3
The multi-part identifier "Cats.CatName" could not be bound.

So in this case, I correctly assigned the alias, but in the ON clause I referenced the actual table name instead of the alias.

The Solution

So the solution is to ensure you’ve assigned all aliases that you might reference later in the query, and also to make sure you use those aliases instead of the table name directly.

So if you’re going to use aliases, like this:

SELECT * FROM Cats c
INNER JOIN Dogs d
ON c.CatName = d.DogName;

Or if you choose not to use aliases, like this:

SELECT * FROM Cats
INNER JOIN Dogs
ON Cats.CatName = Dogs.DogName;

The multi part identifier could not be bound is an SQL error that usually indicates that you are prefixing one or several columns with a table you have not included in the query.The Multi Part Identifier Could Not Be Bound

Artemakis Artemiou is a Senior SQL Server Architect, Author, a 9 Times Microsoft Data Platform MVP (2009-2018). He has over 20 years of experience in the IT industry in various roles. Artemakis is the founder of SQLNetHub and {essentialDevTips.com}. Artemakis is the creator of the well-known software tools Snippets Generator and DBA Security Advisor. Also, he is the author of many eBooks on SQL Server. Artemakis currently serves as the President of the Cyprus .NET User Group (CDNUG) and the International .NET Association Country Leader for Cyprus (INETA). Moreover, Artemakis teaches on Udemy, you can check his courses here.

Views: 13,648

If you get an error telling you that the “The multi-part identifier could not be bound.”, it usually means that you’re prefixing one or more columns with either a table that isn’t included in your query, or an alias that you haven’t actually assigned to a table.

Fortunately, the error message shows you which multi-part identifier is causing the problem.

Example

Here’s an example to demonstrate how to get the error.

SELECT * FROM Cats
INNER JOIN Dogs d
ON c.CatName = d.DogName;

Result:

Msg 4104, Level 16, State 1, Line 3
The multi-part identifier "c.CatName" could not be bound.

In this example, I forget to include an alias for the Cats table.

The error will also occur if you try to reference the table name after you’ve already provided an alias.

Like this:

SELECT * FROM Cats c
INNER JOIN Dogs d
ON Cats.CatName = d.DogName;

Result:

Msg 4104, Level 16, State 1, Line 3
The multi-part identifier "Cats.CatName" could not be bound.

So in this case, I correctly assigned the alias, but in the ON clause I referenced the actual table name instead of the alias.

The Solution

So the solution is to ensure you’ve assigned all aliases that you might reference later in the query, and also to make sure you use those aliases instead of the table name directly.

So if you’re going to use aliases, like this:

SELECT * FROM Cats c
INNER JOIN Dogs d
ON c.CatName = d.DogName;

Or if you choose not to use aliases, like this:

SELECT * FROM Cats
INNER JOIN Dogs
ON Cats.CatName = Dogs.DogName;

The multi part identifier could not be bound is an SQL error that usually indicates that you are prefixing one or several columns with a table you have not included in the query.The Multi Part Identifier Could Not Be Bound

Also, you may try this error if you use an alias you have not assigned to a table. In this guide, you will learn the various causes of this error and how to solve the error. Read on to find out.

Contents

  • What Triggers the Multi Part Identifier Could Not Be Bound Error?
    • – Popular Causes of This Error
    • – Variations of This Error
    • – Example 1: How To Trigger This Error Using Aliases
    • – Example 2: Wrong Use of Dbo Schema
    • – Example 3: Triggering the Error Using Join Statements
  • How To Solve the Error
    • – Solution 1: Use Assigned Aliases
    • – Solution 2: The Correct Use of Schema
    • – Solution 3: Using Joins Correctly
  • Conclusion

What Triggers the Multi Part Identifier Could Not Be Bound Error?

The main reason you are triggering this error in your SQL is that your code is unable to find the source table. For instance, if you have an SQL statement like Table0.OrderDate that triggers this error could indicate that Table0 is nowhere to be found.

In some cases, the table may exist but the SQL is unable to understand your query especially when you use join statements.

Therefore, you can trigger this error if you mix explicit and implicit joins in your query. This is usually allowed, however, you must understand how to accomplish this properly. The thing with explicit joins is that they have higher priority than implicit joins.

Just to refresh your understanding, explicit joins are the ones that you implement using the JOIN keyword. On the other hand, implicit joins are the ones where you specify the join condition using the WHERE clause.

In nutshell, the error “The multi-part identifier could not be bound” typically occurs when you are executing a SQL query, and the query is unable to resolve a multi-part identifier. A multi-part identifier is an identifier in a SQL query that consists of two or more parts, such as a table name and a column name.

– Popular Causes of This Error

This error can be caused by a variety of issues, such as

  • Typos or spelling errors: If you do not spell the multi-part identifier correctly, you will end up triggering this error.
  • Incorrect table or column names: Cross-check the table and column names you are using in your query to establish if they are correct and that they exist in the database.
  • Incorrect table or column alias: If you are using table or column aliases in your query, make sure that they are correctly defined and that they are being used consistently throughout the query.
  • Incorrect table or column references: Make sure that you are referencing the correct tables and columns in your query.
  • Incorrect table or column permissions: It is advisable to ensure that you have the necessary permissions to access the tables and columns you are trying to use in your query.

Also, you will trigger the error if you pass a null value in your where clause in an SQL query, especially when using JDBC. This is misleading since when you do a quick online search, you will end up with something that indicates that your query is wrong.

However, in some cases, that may not be the case. That is a heads-up just in case you come across the same issue.

You may also trigger this error in an updated SQL query. If this happens, crosscheck the JOIN on your table in the field causing the error. It is possibly arising from the lack of JOIN, which will trigger the error in question because of an unknown field. The error you will get will look something like this the multi-part identifier could not be bound update.The Multi Part Identifier Could Not Be Bound Causes

Additionally, you will get this error if you use a field in your query that is not in the table. Suppose you refer to field1 in table1 but the field is in table2.

– Variations of This Error

  • C# the multi-part identifier could not be bound: The error “The multi-part identifier could not be bound” can occur in C# when a SQL query is unable to resolve a multi-part identifier.
  • Mssql the multi-part identifier could not be bound: This error can occur in Microsoft SQL Server when a SQL query is unable to resolve a multi-part identifier.
  • The multi-part identifier could not be bound where clause: The error can occur in a WHERE clause of a SQL query when the query is unable to resolve a multi-part identifier.
  • The multi-part identifier could not be bound sequelize: This error can occur in Sequelize, a popular Node.js ORM for working with databases, when a SQL query is unable to resolve a multi-part identifier.
  • The multi-part identifier could not be bound subquery: The error can occur in a subquery when the subquery is unable to resolve a multi-part identifier.
  • the multi-part identifier could not be bound outsystems: The error “The multi-part identifier could not be bound” can occur in OutSystems when a SQL query is unable to resolve a multi-part identifier.

– Example 1: How To Trigger This Error Using Aliases

Suppose you have a cat table and a dog table, and you want to show the names of all the cats and dogs. You can try to accomplish this as follows in an SQL query:

SELECT * FROM Cat c

INNER JOIN Dog d

ON Cat.CatName = d.DogName;

If you run this query, you will trigger this error. The reason is you correctly assign the Cat table an alias, but in the ON clause, you reference the actual name of the table rather than using the alias.

– Example 2: Wrong Use of Dbo Schema

If you wrongly use the schema(dbo) in your query, you are going to trigger this error. Suppose you write the following SQL server.

SELECT dbo.prod.name

FROM dbo.produce prod

You will struggle with this error in the SQL server if you have multiple joins. Also, if you give an alias name that the SQL server does not accept, you will end up with this error. One alias that SQL server does not accept is “oa”

– Example 3: Triggering the Error Using Join Statements

Suppose you want to use join statements to select details such as sales order, sales detail, and product from a table. You can try to accomplish this as follows:

SELECT * FROM sales.SalesOrder SO

LEFT OUTER JOIN Sales. SalesDetails SD

LEFT OUTER JOIN Produce.Product P

ON SD.ProduceID=p.ProduceID and SO.SalesOrderID=SD.SalesOrderID

If you run this SQL query you trigger the error in question. The reason you will get this error is SO table is not visible from the third part of your join statement and if you try to use the join statement you will get the error.

How To Solve the Error

In this section, you will learn how to fix the multi-part identifier could not be bound error. The solutions, of course, vary based on what is causing the error. Here is a quick look at some of the common solutions to this error.

– Solution 1: Use Assigned Aliases

When you assign aliases to tables, you should take note of those to reference them in later queries. If you already have aliases, make sure you use them instead of directly using the table name.

  • Example

Suppose in your previous example of a database with cat and dog tables, you want to show all the names of the cats and dogs in the tables. You can accomplish this using aliases as follows:

SELECT * FROM Cat c

INNER JOIN Dog d

ON c.CatName = d.DogName;

Also, you can opt to forego the use of aliases as follows:

SELECT * FROM Cat

INNER JOIN Dog

ON Cat.CatName = Dog.DogName;

– Solution 2: The Correct Use of Schema

You should avoid writing the wrong schema in your query. If you have a wrong schema in your query that selects produce from a table, you can correct it as follows:3

SELECT prod.name

FROM dbo.produce prod

– Solution 3: Using Joins Correctly

You can have a strategy for doing inner joins and outer joins in your tables. First, you can do the inner join between your table followed by two left outer joins of your tables. This way you can mix outer joins and inner joins to get outcomes with data from different tables. Using this approach, you avoid using the default comma-separated syntax, which can miss rows in the desired join.

The best approach is to start with the inner join between tables that have matching data. After you are done, you can move to outer joins to attempt to collect data from other tables. The outer joins will not filter out the outcome if the outer join table does not have corresponding data.

Also, this applies if the outer join table does meet the condition you set in the condition or predicate.

Here is an example of how you can use a multi-part identifier in your query.

SELECT * FROM sales.SalesOrder SO

LEFT OUTER JOIN Sales. SalesDetails SD

ON SO.SalesOrderID=SD.SalesOrderID

LEFT OUTER JOIN Produce.Product P

ON SD.ProduceID=p.ProduceID

In this query, the SO.SalesOrderID=SD.SalesOrderID statement comes immediately after your first join, where the SO table is completely visible.

Conclusion

In this post, you have learned about the multi-part identifier could not be bound error. Here is a quick look at what you have covered in this article:

  • The error typically occurs when you are executing a SQL query, and the query is unable to resolve a multi-part identifier
  • This error arises from a variety of issues, such as spelling errors, incorrect table or column names, aliases, references, or permissions
  • To solve the error, you need to carefully examine the query and identify if you are correctly using table or column names, aliases, and references

With this understanding, you will be able to handle this error when it pops up in the future.

  • Author
  • Recent Posts

Position is Everything

Your Go-To Resource for Learn & Build: CSS,JavaScript,HTML,PHP,C++ and MYSQL. Meet The Team

Position is Everything

  • Remove From My Forums
  • Question

  • Hi,

    When I try execute one query in SQL 2k5, with alias in order by clausule, I retrieve the follow message:

    Server: Msg 4104, Level 16, State 1, Line 1
    The multi-part identifier «alias.fields» could not be bound.

    Where alias is a any alias and, fields is a field of the table with alias.

    Already exists one fix to patch this?

    Thanks

Answers

  • In your select statement there is no reference to this table (rentalCostTable), so that’s why you’re getting the error:

    SELECT locationTypesTable.locationTypes, rentalCostTable.rentalCost, PFR.shortDescription, PFR.propertyRef, propertyTypesTable.propertyType, PFR.numBeds
     FROM propertysForRentTable PFR
     INNER JOIN
      propertyTypesTable ON PFR.typeOfProperty = propertyTypesTable.keyID
     INNER JOIN
      locationTypesTable ON PFR.location = locationTypesTable.keyID 

    In order to resolve the error, you must include this table in the FROM clause, e.g. JOIN with it based on some field.

    SELECT locationTypesTable.locationTypes, rentalCostTable.rentalCost, PFR.shortDescription, PFR.propertyRef, propertyTypesTable.propertyType, PFR.numBeds
     FROM propertysForRentTable PFR
     INNER JOIN
      propertyTypesTable ON PFR.typeOfProperty = propertyTypesTable.keyID
     INNER JOIN
      locationTypesTable ON PFR.location = locationTypesTable.keyID 
    
    INNER JOIN rentalCostTable ON
    PFR.RentalID = rentalCostTable.RentalID -- use the actual field to join the tables

    Premature optimization is the root of all evil in programming. (c) by Donald Knuth

    Naomi Nosonovsky, Sr. Programmer-Analyst

    My blog

    • Marked as answer by

      Wednesday, September 15, 2010 11:25 PM

  • This was a bug in the older versions of SQL Server. We fixed the problems with the ORDER BY clause in SQL Server 2005. This is documented under the following topic:

    You should also check out the other backward compatibility topics:

    Also, I should note that the query above will run fine if the database compatibility level is set to 80 or below. You can do this by using the sp_dbcmptlevel system SP but please read the corresponding topic in Books Online before going this route. The database compatibility level for databases upgraded from SQL Server will automatically be at 80 so your existing code should run fine.

  • Greetings.  I ran into this because I had alias conflicts where the table name and the field name were the same.  Once I gave the table a true alias (e.g. «z3») with no conflict,
    it worked fine.

     UPDATE #LocTracker

    SET ErrorCode
    = 3
    —‘Unknown ZIP3’

    FROM #LocTracker lt

    LEFT
    OUTER
    JOIN US_TC_RMS_DB_MGMT..ZIP3
    ON zip3.ZIP3
    =
    LEFT(lt.POSTALCODE,3)

    WHERE lt.POSTALCODE
    is
    null

    AND ErrorCode
    = 0

     Gave me this error:

    The multi-part identifier «zip3.ZIP3» could not be bound.

    Certainly zip3.ZIP3 referencing is not Best Practices.

    UPDATE can be very tricky. Note above that #LocTracker is used after the UPDATE then after the FROM with alias. While valid T-SQL, I always found it confusing.

    Referring to the sample below, I just put the table name with alias after FROM, and
    after UPDATE I use the table alias. I also use table alias for each column.

    Same consideration if you are JOINing to subselect (derived table).

    The advantage of such an approach is that you take out the guesswork from the query.
    You tell precisely the database engine what should it do.


    USE tempdb; SELECT * INTO SOH FROM AdventureWorks2008.Sales.SalesOrderHeader SELECT * INTO SOD FROM AdventureWorks2008.Sales.SalesOrderDetail -- Bad reference I meant to type b.ProductID UPDATE a SET a.TotalDue = a.TotalDue * 1.05 FROM SOH a INNER JOIN SOD b ON a.SalesOrderID = b.SalesOrderID WHERE c.ProductID != 800 GO /* Msg 4104, Level 16, State 1, Line 12 The multi-part identifier "c.ProductID" could not be bound. */ -- Correct reference, successful query UPDATE a SET a.TotalDue = a.TotalDue * 1.05 FROM SOH a INNER JOIN SOD b ON a.SalesOrderID = b.SalesOrderID WHERE b.ProductID != 800 GO -- (31366 row(s) affected) DROP TABLE SOH DROP TABLE SOD

    Kalman Toth
    New Book:
    Beginner Database Design & SQL Programming Using Microsoft SQL Server 2016

    • Marked as answer by
      Kalman Toth
      Tuesday, November 15, 2011 9:25 PM
    • Edited by
      Kalman Toth
      Friday, November 10, 2017 10:03 AM

  • Mine was a total bonehead mistake.  I mis-spelled the table name in the SELECT field.

    IntelliSense may be helpful (starting with SQL Server 2008):


    • Marked as answer by
      Kalman Toth
      Tuesday, November 15, 2011 9:24 PM
    • Edited by
      Kalman Toth
      Thursday, November 9, 2017 1:08 AM

    • Proposed as answer by
      Naomi N
      Tuesday, December 14, 2010 7:16 PM
    • Marked as answer by
      Kalman Toth
      Wednesday, March 30, 2011 1:07 AM
    • Edited by
      Kalman Toth
      Thursday, November 9, 2017 1:08 AM

Понравилась статья? Поделить с друзьями:
  • Sql server ошибка the login failed
  • Sql server ошибка not support the language
  • Sql server ошибка 5023 при запуске
  • Sql server ошибка 26 при удаленном соединении
  • Sql server операция create file вызвала ошибку операционной системы