SQL Help

Soldato
Joined
18 Oct 2002
Posts
7,515
Location
Maidenhead
Hi all,

I have a table named Credit_Accounts_Import. I am trying to update the table Credit_Accounts_Copy column PID_Other where the column Account_Name is the same in both tables.

Credit_Accounts_Import has the same structure as Credit_Accounts_Copy, but around half of the rows as it only contains data where PID_Other is not null.

Any help would be appreciated.
Thanks
Paul
 
Could you post a few sample rows (make up the data if it's sensitive, obviously) from both tables?
 
You're looking at something like:

Code:
UPDATE Credit_Accounts_copy 	
         SET PID_Other = {insert constant or query for data reference to update to}
WHERE EXISTS
  ( SELECT Account_Name
    FROM Credit_Accounts_Import
    WHERE Credit_Accounts_Copy.Account_Name = Credit_Accounts_Import.Account_Name);

Exact form would depend on your table structure, and someone else might be able to advise a more efficient way of doing it :)
 
Thanks chaps. In the end I used

Code:
UPDATE	[Credit_Accounts_Copy]
SET 		PID_Other = [Credit_Accounts_Import].[PID_Other]
FROM		[Credit_Accounts_Copy] INNER JOIN [Credit_Accounts_Import] ON [Credit_Accounts_Copy].[Account_Number] = [Credit_Accounts_Import].[Account_Number]
 
Back
Top Bottom