Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Update between tables

Status
Not open for further replies.

nzgirl

Programmer
Feb 26, 2003
72
NZ
I'm going round in circles here :-(
I'm updating the Name field in my database. And I want to keep a backup incase something goes wrong (the format needs to be changed)
So I have table: TempData with fields 'FirstName', 'LastName', 'Email' and 'Tmp' as my backup
and table: Recipients with Fields 'FirstName', 'LastName', 'Email' and 'RID' as my actual data.
If I need to copy from TempData to Recipients -whats a good way?
Email is unqiue and won't be changed.

select TempData.*, Recipients.RecipientID as RID
into #TEMP1 from Recipients
left join TempData on Recipients.email = TempData.email
where Recipients.email <>&quot;&quot; and Recipients.email is not Null
UPDATE Recipients
Set FirstName = #TEMP1.FirstName
from #TEMP1, Recipients
where #TEMP1.Email = REcipients.Email

leaves me with lots of Null records... and I'm just lost.. and I've had too much coffee :-(

Any pointers appreciated!!
:)
 
It assigns records that aren't in the TempData Table but are in the Recipients Table to Null.
I'm going to blame this on bad data in my trial database and try it
:)
 
Can you elaborate a little? What do you mean by &quot;if something goes wrong&quot;? If you want to make sure everything worked so that you are sure not to end up with a &quot;bad&quot; name, simply put the update into a transaction like:

Code:
BEGIN TRANSACTION
--Perform your update and check result
IF result < 0
    ROLLBACK TRANSACTION
ELSE
    COMMIT TRANSACTION
END

The whole thing is based though on your interpretation of something going wrong and how it can be checked
 
I need to update Table1 with Table2 values...
the only link between the tables is a field called Email.
I need to update 200 records and I want to do something like
update Table1 set field1 =
select a.field1 from Table2 a, Table1 b where a.Email = b.Email
but of course that brings back too many rows....

Any ideas?
:)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top