p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   SQL Language (http://p2p.wrox.com/forumdisplay.php?f=100)
-   -   How to Update one table with other table data? (http://p2p.wrox.com/showthread.php?t=42893)

ramk_1978 May 23rd, 2006 01:48 AM

How to Update one table with other table data?
 
Hi,

Table 1
--------
EId FirstName LastName
---------------------------------
1 sdf df
2 sdf sdf
3 sdfd sdfsdf


Table 2
--------
EId FirstName LastName
----------------------------------
1 NULL NULL
2 NULL NULL
3 NULL NULL


How to update Table2's firstname and lastname column data using table1's data?

Ramkumar A.D.


A.D.Ramkumar

Jack Britton May 25th, 2006 02:14 PM

Ramkumar:

Try this SQL statement:

UPDATE TBL, tblEmployees SET TBL.Firstname = TBL!Firstname, TBL.Lastname = [TBL]![Lastname]
WHERE (((TBL.Firstname)=[tblEmployees]![FirstName]) AND ((TBL.Lastname)=[tblEmployees]![LastName]));

TBL was a test table I set up in Access to make sure it worked. It does. I hope this helps. I don't know what type of RDBMS you are using but this does work in Access.

Thanks,
Jack Britton


ramk_1978 May 26th, 2006 12:51 AM

Hi,

I am using SQL Server 2000 for this and the reply that i got is:


update table2 set firstname=table1.firstname, lastname=table1.lastname from table1,table2
where table1.eid=table2.eid


A.D.Ramkumar


All times are GMT -4. The time now is 06:52 PM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.