DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 6 of 6
  1. #1
    Join Date
    Nov 2007
    Posts
    23

    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

  2. #2
    Join Date
    Nov 2003
    Location
    Portland, OR
    Posts
    8,387
    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!

  3. #3
    Join Date
    Nov 2007
    Posts
    23
    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.

  4. #4
    Join Date
    Nov 2003
    Location
    Portland, OR
    Posts
    8,387
    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!

  5. #5
    Join Date
    Nov 2007
    Posts
    23
    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

  6. #6
    Join Date
    Nov 2007
    Posts
    23
    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

  1. Updating on screen text fields with multiple table data
    By William Ed Carden in forum VB Classic
    Replies: 2
    Last Post: 10-17-2005, 05:09 PM
  2. ADOX Table Type is null when created
    By Sheir Rahman Ali in forum VB Classic
    Replies: 1
    Last Post: 01-26-2001, 10:04 AM
  3. Replies: 0
    Last Post: 12-01-2000, 01:39 PM
  4. Multi-row calculations
    By Bob Hines in forum Database
    Replies: 7
    Last Post: 04-27-2000, 11:14 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


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


Sponsored Links