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
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Self update query help

Author  Topic 

mshsilver
Posting Yak Master

112 Posts

Posted - 2009-03-11 : 08:38:53
Hi,

I have 190 records where i want to pull the company name from other records in this table in to the company field for these records where field unqiueid =user8.

Below is a select query that gives me the reults i want i just need to copy data from entity.company to list.company, i just don't know how :-) Anyone got any ideas?


Thanks for any help.




SELECT entity.uniqueid, list.user8,entity.company, list.company,entity.contact,list.contact
FROM wce_contact AS entity LEFT OUTER JOIN wce_contact AS list
ON entity.uniqueid = list.user8 where list.user9 = 'scw'

heavymind
Posting Yak Master

115 Posts

Posted - 2009-03-11 : 10:51:19
do you mean you want to self-join this table for the records where CompanyName is Null by user8 = uniqueid ?

then you should do something like
SELECT User8, User9, User12, Contact, Company = isnull ( v.Company, select company from wce_contact v2 where v2.uniqueid = v.User8)
FROM wce_contact v



Thanks, Vadym
MCITP DBA 2005/2008
Chief DBA at http://www.db-staff.com
Go to Top of Page

mshsilver
Posting Yak Master

112 Posts

Posted - 2009-03-11 : 11:54:11
Hi Could'nt get that working but got it working with the code above. Now i just need help with the update query. Thanks for your input.
Go to Top of Page
   

- Advertisement -