| 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.ArchiveSET 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 9Subquery 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 |
 |
|
|
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 |
 |
|
|
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 | EmployeeIDCN=testuser,dc=domain | 123456I 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. |
 |
|
|
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 USET Description = T.EmployeeIDFROM Users AS UINNER JOIN TEMP_Users AS T ON T.DISNAME = U.DN |
 |
|
|
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 USET Description = T.EmployeeIDFROM Users AS UINNER 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! |
 |
|
|
Mark79
Starting Member
7 Posts |
Posted - 2009-10-22 : 21:08:38
|
| Sorry the error is:'The Multi-part identifier could not be BOUND' |
 |
|
|
Mark79
Starting Member
7 Posts |
Posted - 2009-10-25 : 18:50:31
|
Anyone able to help please? |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
Mark79
Starting Member
7 Posts |
Posted - 2009-10-27 : 23:54:50
|
| Thank you, I think I understand the issue now. |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
|