Link to home
Start Free TrialLog in
Avatar of printmedia
printmedia

asked on

The multi-part identifier could not be bound in SQL Server 2008

Hi all.

I get a multi-part identifier error when I run the code below.

It lists all of the linked server table and fields in the error. What am I doing incorrectly?

Thank you in advance.

update t1
set [myID]  = t2.myID
from GPO_Rosters.dbo.All_Rosters t1 join 
( SELECT     CAST([myLinkedServer].[myDB].dbo.tblReference.Division AS nvarchar(10)) 
                      + N'-' + CAST([myLinkedServer].[myDB].dbo.tblReference.ReferenceID AS nvarchar(10)) AS myID, [myLinkedServer].[myDB].dbo.tblGPODetails.GPOName, 
                      [myLinkedServer].[myDB].dbo.GPOSub1A.CompanyNumber
FROM         [myLinkedServer].[myDB].dbo.GPOSub1A INNER JOIN
                      [myLinkedServer].[myDB].dbo.tblGPODetails ON 
                      [myLinkedServer].[myDB].dbo.GPOSub1A.GPODetailsID = [myLinkedServer].[myDB].dbo.tblGPODetails.GPODetailsID INNER JOIN
                      [myLinkedServer].[myDB].dbo.tblReference ON 
                      [myLinkedServer].[myDB].dbo.tblGPODetails.ReferenceID = [myLinkedServer].[myDB].dbo.tblReference.ReferenceID
WHERE     ([myLinkedServer].[myDB].dbo.GPOSub1A.CompanyNumberStatus = N'Active')) t2 on t1.[GPO Name] = t2.GPOName AND t1.[Company Number] = t2.CompanyNumber
where t1.[myID] IS NULL

Open in new window

==========================================
**Author Accepted Solution, Original Points: 500**
Avatar of Jim Horn
Jim Horn
Flag of United States of America image

<wild guess>

>update t1
>set [myID] = ...
Eyeballeth thy tables in this query and see if there is more than one with a column named myId.
Assuming yes, you'll have to prefix the above myID with the correct able name.
Check the column names in GPO_Rosters.dbo.All_Rosters. Do you have space in these fields:
[GPO Name], [Company Number]

Open in new window

Avatar of printmedia
printmedia

ASKER

The columns names do not have spaces.
OK then, modify your statement to this and see if it works:
update t1
set [myID]  = t2.myID
from GPO_Rosters.dbo.All_Rosters t1 join 
( SELECT     CAST([myLinkedServer].[myDB].dbo.tblReference.Division AS nvarchar(10)) 
                      + N'-' + CAST([myLinkedServer].[myDB].dbo.tblReference.ReferenceID AS nvarchar(10)) AS myID, [myLinkedServer].[myDB].dbo.tblGPODetails.GPOName, 
                      [myLinkedServer].[myDB].dbo.GPOSub1A.CompanyNumber
FROM         [myLinkedServer].[myDB].dbo.GPOSub1A INNER JOIN
                      [myLinkedServer].[myDB].dbo.tblGPODetails ON 
                      [myLinkedServer].[myDB].dbo.GPOSub1A.GPODetailsID = [myLinkedServer].[myDB].dbo.tblGPODetails.GPODetailsID INNER JOIN
                      [myLinkedServer].[myDB].dbo.tblReference ON 
                      [myLinkedServer].[myDB].dbo.tblGPODetails.ReferenceID = [myLinkedServer].[myDB].dbo.tblReference.ReferenceID
WHERE     ([myLinkedServer].[myDB].dbo.GPOSub1A.CompanyNumberStatus = N'Active')) t2 on t1.[GPOName] = t2.GPOName AND t1.[CompanyNumber] = t2.CompanyNumber
where t1.[myID] IS NULL

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of printmedia
printmedia

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I've requested that this question be closed as follows:

Accepted answer: 0 points for printmedia's comment #a40199194

for the following reason:

I figured it out on my own.
Just to be clear your original code is not exactly as the last code. If you can't see the difference I am showing you the two lines below:
on t1.[GPO Name] = t2.GPOName AND t1.[Company Number] = t2.CompanyNumber

Open in new window

on t1.[GPOName] = t2.GPOName AND t1.[CompanyNumber] = t2.CompanyNumber

Open in new window

The first line from the original code, that was not worked. The second line is from the code I have provided and you have copied as your last comment, which you think is your
exact original code
Go figure....
chaau,

The code you provided is incorrect. The field name in t1.[GPO Name] has a space while the field name in t2.GPOName does not. That's the way the fields are in each respective table. So doing it your way gives me another error because t1.[GPOName] and t1.[CompanyNumber] DOES NOT exist.
chaau.

I tried your code again:

update t1
set [myID]  = t2.myID
from GPO_Rosters.dbo.All_Rosters t1 join 
( SELECT     CAST([myLinkedServer].[myDB].dbo.tblReference.Division AS nvarchar(10)) 
                      + N'-' + CAST([myLinkedServer].[myDB].dbo.tblReference.ReferenceID AS nvarchar(10)) AS myID, [myLinkedServer].[myDB].dbo.tblGPODetails.GPOName, 
                      [myLinkedServer].[myDB].dbo.GPOSub1A.CompanyNumber
FROM         [myLinkedServer].[myDB].dbo.GPOSub1A INNER JOIN
                      [myLinkedServer].[myDB].dbo.tblGPODetails ON 
                      [myLinkedServer].[myDB].dbo.GPOSub1A.GPODetailsID = [myLinkedServer].[myDB].dbo.tblGPODetails.GPODetailsID INNER JOIN
                      [myLinkedServer].[myDB].dbo.tblReference ON 
                      [myLinkedServer].[myDB].dbo.tblGPODetails.ReferenceID = [myLinkedServer].[myDB].dbo.tblReference.ReferenceID
WHERE     ([myLinkedServer].[myDB].dbo.GPOSub1A.CompanyNumberStatus = N'Active')) t2 on t1.[GPOName] = t2.GPOName AND t1.[CompanyNumber] = t2.CompanyNumber
where t1.[myID] IS NULL

Open in new window


And I still get the error.
That's OK, as long as the query works for you