mohamed faiz mohamed faiz - 3 years ago 95
SQL Question

How do I solve "couldn't be bound error" in SQL Server in my criteria?

I have a table called

Transfer
. When I try to perform
LEFT JOIN
it's not detecting that table from database.

Here is my query:

Select
tmp.ID,
tmp.Name,
st.Store,
Number
FROM
#tmpStore tmp
LEFT JOIN #store st on st.ID = tmp.ID
LEFT JOIN Transfer tr on tr.number = st.number --Here is error


ERROR


Incorrect syntax near the keyword 'Transfer'.


When I move the mouse on tr.number, it throws


The multi part identifier
tr.number
couldn't be bound


Only this particular table is showing an error while doing LEFT JOIN. When I do join with another table, it's not showing an error.

Answer Source

Transfer is a reserved word used in ALTER SCHEMA , so you can execute your query like below:

Select
    tmp.ID,
    tmp.Name,
    st.Store,
    Number
FROM
    #tmpStore tmp
LEFT JOIN #store st on st.ID = tmp.ID
LEFT JOIN DBName.Schema.[Transfer] tr on tr.number = st.number;

For more information see: ALTER SCHEMA (Transact-SQL)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download