SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Help regarding Update statement...
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

ajay_hk
Starting Member

4 Posts

Posted - 04/28/2008 :  13:42:23  Show Profile  Reply with Quote
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

USA
37296 Posts

Posted - 04/28/2008 :  13:48:55  Show Profile  Visit tkizer's Homepage  Reply with Quote
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

India
52325 Posts

Posted - 04/28/2008 :  13:49:55  Show Profile  Reply with Quote
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 
Go to Top of Page

ajay_hk
Starting Member

4 Posts

Posted - 04/28/2008 :  13:56:27  Show Profile  Reply with Quote
That worked...Many thanks for your help @tkizer and @visakh16.
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000