Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 ERROR:The Multi-part identifier could not be found

Author  Topic 

Mark79
Starting Member

7 Posts

Posted - 2009-10-20 : 21:19:52
Hello all, I'm receiving the above error message from the following code:

UPDATE [Directory].dbo.Archive
SET Archive.ArchiveDescription =
( SELECT DISTINCT EMPLOYEEID
FROM [BILLINGTEST].[dbo].[TEMP_USERS]
INNER JOIN Directory.dbo.MailboxEntry
ON Directory.dbo.MailboxEntry.ADMbxDN = billingtest.dbo.TEMP_users.DISName)
WHERE [Directory].[dbo].[MailboxEntry].ADMbxDN=[BILLINGTEST].[dbo].[TEMP_USERS].DISNAME)
WHERE EXISTS
( SELECT DISTINCT DISNAME
FROM [BILLINGTEST].[dbo].[TEMP_USERS]
INNER JOIN Directory.dbo.MailboxEntry
ON Directory.dbo.MailboxEntry.ADMbxDN = billingtest.dbo.TEMP_users.DISNAME
WHERE [BILLINGTEST].[dbo].[TEMP_USERS].DISNAME = [Directory].[dbo].[MailboxEntry].[ADMbxDN]);



I'm trying to update a table in one database with an employeeID out of a table in another database.

Many thanks,
Mark

Mark79
Starting Member

7 Posts

Posted - 2009-10-20 : 22:38:00
Sorry, with the above code I get the error:

quote:
Msg 512, Level 16, State 1, Line 9
Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.



But if I comment out the INNER JOIN statements then I get the error "Multi-part Identifier could not be found"

I'm really not sure which way to go here....

thanks again,
Mark
Go to Top of Page

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2009-10-21 : 12:07:17
Unfortunately your query doesn't make any sense as it is written. Is there some relation between the Archive table and the other tables? Can you describe in words what you want to accomplish? If you have sample data and expected output, that would also help This may also help: http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx
Go to Top of Page

Mark79
Starting Member

7 Posts

Posted - 2009-10-21 : 18:01:09
I thought that maybe the case.... :)

I have a VBScript which exports two fields from Active Directory (DN and EmployeeID) and stores them in a .txt file.

DN | EmployeeID
CN=testuser,dc=domain | 123456

I then need to match the DN with the DN stored in a database and update another field with the employeeID. From what I could find, it seemed easier to BULK INSERT the text file into a table, then use the UPDATE command to update the field with the correct employeeID. My query does work if I have the tables in the same database. The problem is I cannot create and drop the temp_users table into the production database, therefore need to create the Temp_users in a different database, but still on the same SQL server.

This is the code that works for two tables in the same database, how do I make it work for two seperate databases?

CREATE TABLE [BILLINGTEST].[dbo].[TEMP_USERS]
( DISNAME NVARCHAR(255) NULL,
EMPLOYEEID NVARCHAR(255) NULL
);

BULK INSERT [BILLINGTEST].[dbo].[TEMP_USERS] FROM 'e:\billing\users.txt'
WITH ( FIELDTERMINATOR ='|', FIRSTROW = 2 )

UPDATE Users
SET Users.Description =
( SELECT TEMP_Users.EMPLOYEEID
FROM TEMP_Users
WHERE TEMP_Users.DISNAME = Users.DN)
WHERE EXISTS
( SELECT TEMP_Users.DISNAME
FROM TEMP_Users
WHERE TEMP_Users.DISName = Users.DN);

DROP TABLE [BILLINGTEST].[dbo].[TEMP_USERS]


Make sense? Thanks.
Go to Top of Page

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2009-10-21 : 18:14:34
Ahh I see. There are several ways to do that. I belive this will work for you:
UPDATE 
U
SET
Description = T.EmployeeID
FROM
Users AS U
INNER JOIN
TEMP_Users AS T
ON T.DISNAME = U.DN
Go to Top of Page

Mark79
Starting Member

7 Posts

Posted - 2009-10-21 : 21:28:10
quote:
Originally posted by Lamprey

Ahh I see. There are several ways to do that. I belive this will work for you:
UPDATE 
U
SET
Description = T.EmployeeID
FROM
Users AS U
INNER JOIN
TEMP_Users AS T
ON T.DISNAME = U.DN




Thanks you! Very close, but the line
ON.T.DISNAME = U.DN
doesn't quite work as DN is from another table called ExchangeMailboxEntry. I'm getting the error 'The Multi-part identifier could not be found' again when I change the line to
ON T.DISNAME = database.dbo.ExchangeMailboxEntry.DN


Thank you again for you help!
Go to Top of Page

Mark79
Starting Member

7 Posts

Posted - 2009-10-22 : 21:08:38
Sorry the error is:

'The Multi-part identifier could not be BOUND'
Go to Top of Page

Mark79
Starting Member

7 Posts

Posted - 2009-10-25 : 18:50:31
Anyone able to help please?
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2009-10-25 : 23:34:34
You'll need to add a join to ExchangeMailboxEntry if DN is from that table. I don't see in your previous posts how the relation is to that table, so I'm unable to update your code.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog

"Let's begin with the premise that everything you've done up until this point is wrong."
Go to Top of Page

Mark79
Starting Member

7 Posts

Posted - 2009-10-27 : 23:54:50
Thank you, I think I understand the issue now.
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2009-10-28 : 13:58:09
You're welcome.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog

"Let's begin with the premise that everything you've done up until this point is wrong."
Go to Top of Page
   

- Advertisement -