user794846
user794846

Reputation: 1931

MS-SQL query issue: the multi-part identifier not be bound, Invalid object name 'jt0

I dont normally use MS-SQL and I am little confused about whats actually wrong with this query.

 SELECT TOP 101 * FROM (
              SELECT  calls.id , calls.recurring_source , calls.status , calls.direction , calls.name  , jt0.name samaw_call_lists_calls_name, jtl0.samaw_call_lists_callssamaw_call_lists_ida samaw_call_lists_callssamaw_call_lists_ida , LTRIM(RTRIM(ISNULL(contacts.first_name,'')+N' '+ISNULL(contacts.last_name,''))) contact_name, jtl1.contact_id contact_id, calls.parent_id , calls.parent_type , calls.date_start , calls.date_entered , calls.assigned_user_id  , ROW_NUMBER()
                                OVER (ORDER BY calls.direction) AS row_number
                                FROM calls  LEFT JOIN calls_cstm ON calls.id = calls_cstm.id_c   LEFT JOIN  samaw_call_lists_calls_c jtl0 ON calls.id=jtl0.samaw_call_lists_callscalls_idb AND jtl0.deleted=0

 LEFT JOIN   jt0 ON jt0.id=jtl0.samaw_call_lists_callssamaw_call_lists_ida AND jt0.deleted=0
 AND jt0.deleted=0  LEFT JOIN  calls_contacts jtl1 ON calls.id=jtl1.call_id AND jtl1.deleted=0

LEFT JOIN  contacts contacts ON contacts.id=jtl1.contact_id AND contacts.deleted=0
AND contacts.deleted=0 where calls.deleted=0 
                            ) AS a
                            WHERE row_number > 0

This query was auto generated by script and gives the following error when its run: Invalid object name 'jt0

When I try to run is manually I got this message:

The multi-part identifier "jt0.name" could not be bound.

Is it obvious to anyone what the problem is here?

Upvotes: 0

Views: 361

Answers (2)

Jatin Patel
Jatin Patel

Reputation: 2104

looks like you are missing actual table name for the alias jt0 here,

LEFT JOIN   jt0 ON jt0.id=jtl0.samaw_call_lists_callssamaw_call_lists_ida AND jt0.deleted=0

there should be actual table name between LEFT JOIN and jt0.

Upvotes: 0

Slan
Slan

Reputation: 560

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 [].

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 Management Studio supports intellisense out of the box, although it isn't quite as complete as the redgate version.

Upvotes: 2

Related Questions