-
Filling up data from a newly created column from an old table?
How do you fill up a newly created column with data coming from another table if their Emp_ID matches?
Is it possible to using stored procedures?
Table1
Emp_ID Emp_Name
1001 Smith
1002 Dexter
1003 Peter
1004 John
Table2
Emp_ID Date_Hired
1001 01/15/95
1002 01/16/96
1004 02/18/94
1005 02/19/94
Table1
Emp_ID Emp_Name Date_Hired(created column)
1001 Smith 01/15/95
1002 Dexter 01/16/96
1003 Peter <NULL>
1004 John 02/18/94
thanks in advance
-
What kind of database? Do you want to populate the Date_Hired column in real time (each time a new record is added), or just once based on existing data?
Phil Weber
http://www.philweber.com
Please post questions to the forums, where others may benefit.
I do not offer free assistance by e-mail. Thank you!
-
The db is sql server 2000.
I already set Date_Hired column to getdate() by default when i created the column but since the table is already existing, i need to populate the existing data from another "an activity logging" table.
-
Try this:
UPDATE Table1, Table2
SET Table1.Date_Hired = Table2.Date_Hired
WHERE Table1.Emp_ID = Table2.Emp_ID
Phil Weber
http://www.philweber.com
Please post questions to the forums, where others may benefit.
I do not offer free assistance by e-mail. Thank you!
-
Tried your code and it didnt worked. It seems "Update" wont allow declaring 2 tables.
I tried another this code yet still it didnt worked
Update Table1
SET Table1.date_hired = (select Table2.date_hired from Table2)
Where Table1.emp_id = (Select Table2.emp_id from Table2)
it always give this error warning
"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."
any help?
Thanks in advance
-
Finally managed to solve the problem.
the proper way was
Update Table1
Set date_hired = Table2.date_hired
From Table2
Where table1.emp_id = table2.emp_id
thanks
Similar Threads
-
By William Ed Carden in forum VB Classic
Replies: 2
Last Post: 10-17-2005, 05:09 PM
-
By Sheir Rahman Ali in forum VB Classic
Replies: 1
Last Post: 01-26-2001, 10:04 AM
-
By Toby in forum Database
Replies: 0
Last Post: 12-01-2000, 01:39 PM
-
By Bob Hines in forum Database
Replies: 7
Last Post: 04-27-2000, 11:14 AM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks