Results 1 to 2 of 2
  1. #1
    Join Date
    Sep 2002
    Posts
    18

    Unanswered: Insert Query Problem

    Table: Dept
    Dept_ID Dept_ Name
    {7CFBF07C-0123} Engineering
    {864CB2DF-519E} Planning
    {344FDBBF-5FDD} Accounting

    _
    Table: Employee
    Emp_ID FN LN Dept_ID
    5562 John Smith
    _
    __
    I have the above two tables. John Smith is from the Engineering Dept. I tried to insert his info _in the Employee but I couldn’t because of the Dept_ID integrity. How can I write an Insert statement to automatically get the Dept_ID from the Dept Table and insert in the Employee table along for the Emp_ID, FN, LN which are known?

    Check this http://www.geocities.com/oozypal/IUI/ if you can't read the tables.

  2. #2
    Join Date
    Sep 2002
    Location
    Atlanta, GA USA
    Posts
    19

    Arrow Re: Insert Query Problem

    One way is as follows:

    INSERT INTO Employee (Emp_ID, FN, LN, Dept_ID)
    SELECT 5562, 'John', 'Smith', D.Dept_ID
    FROM Dept AS D
    WHERE D.Dept_Name = 'Engineering'


    Originally posted by oozypal
    Table: Dept
    Dept_ID Dept_ Name
    {7CFBF07C-0123} Engineering
    {864CB2DF-519E} Planning
    {344FDBBF-5FDD} Accounting

    _
    Table: Employee
    Emp_ID FN LN Dept_ID
    5562 John Smith
    _
    __
    I have the above two tables. John Smith is from the Engineering Dept. I tried to insert his info _in the Employee but I couldn’t because of the Dept_ID integrity. How can I write an Insert statement to automatically get the Dept_ID from the Dept Table and insert in the Employee table along for the Emp_ID, FN, LN which are known?

    Check this http://www.geocities.com/oozypal/IUI/ if you can't read the tables.
    HueyStLoui

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •