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.
========== ======
**Author Accepted Solution, Original Points: 500**
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
==========================**Author Accepted Solution, Original Points: 500**
Check the column names in GPO_Rosters.dbo.All_Roster s. Do you have space in these fields:
[GPO Name], [Company Number]
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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.
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
on t1.[GPOName] = t2.GPOName AND t1.[CompanyNumber] = t2.CompanyNumber
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 yourexact original codeGo figure....
ASKER
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.
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.
Ok then. When you have time just reread my answer at https://www.experts-exchange.com/questions/28475480/The-multi-part-identifier-could-not-be-bound-in-SQL-Server-2008.html?anchorAnswerId=40198242#a40198242 and compare it with yours.
ASKER
chaau.
I tried your code again:
And I still get the error.
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
And I still get the error.
That's OK, as long as the query works for you
>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.