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
 Help regarding Update statement...

Author  Topic 

ajay_hk
Starting Member

4 Posts

Posted - 2008-04-28 : 13:42:23
Hi all,

I have a table called "dimcustomer" which has 25 columns in it out of which account name is one of them. There is another table called "dw_Organisation" which comes from a different source which also has the account name in it. There are about 15K rows in the "Dimcustomer" table where the account names are nulls. I want to use the account names in the "dw_Organisation" table to update the account names in the "Dimcustomer" table. The join info and SQL i'm using is as given below...

UPDATE dimcustomer 
SET account = (SELECT b.name
FROM dimcustomer a, tibcostg..dw_organisation b
where a.GUID = b.commonid and a.account is null)
WHERE EXISTS
(SELECT b.name
FROM dimcustomer a, tibcostg..dw_organisation b
where a.GUID = b.commonid and a.account is null)


The above SQL throws me the following error...
quote:
Server: Msg 512, Level 16, State 1, Line 1
Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.
The statement has been terminated.


It would be really helpful if you could advice me on where things are going wrong on the above SQL...Many thanks for your help.

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-04-28 : 13:48:55
Try this:

UPDATE a
SET account = b.name
FROM dimcustomer a
INNER JOIN tibcostg..dw_organisation b
ON a.GUID = b.commonid
WHERE a.account IS NULL

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-04-28 : 13:49:55
[code]UPDATE a
SET a.account = b.name
FROM dimcustomer a
INNER JOIN tibcostg..dw_organisation b
ON a.GUID = b.commonid
WHERE a.account is null
[/code]
Go to Top of Page

ajay_hk
Starting Member

4 Posts

Posted - 2008-04-28 : 13:56:27
That worked...Many thanks for your help @tkizer and @visakh16.
Go to Top of Page
   

- Advertisement -