Sub Query in INSERT statement


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 5 of 5

Thread: Sub Query in INSERT statement

  1. #1
    Join Date
    Jan 2006
    Posts
    67

    SQL Server: Sub Query in INSERT statement

    How do you use a subquery to look up a value in another table to insert it into a new field?
    Last edited by CB77; 02-23-2007 at 10:05 PM.

  2. #2
    Join Date
    Nov 2003
    Location
    Portland, OR
    Posts
    8,387
    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
    Jan 2006
    Posts
    67
    Thanks but that doesn't help me. This is what I am trying to do but get errors

    INSERT INTO SportEmployee
    (EmployeeLastName, EmployeeFirstName, EmployeeMI, EmployeeDOB, EmployeeManagerID, EmployeeHireDate, EmployeeHomePhone, EmployeePhotoFilename, EmployeeCommission, DepartmentID, EmployeeUserName, EmployeePassword)
    VALUES ('Lee', 'Jim', 'R', 15/07/1977, (SELECT EmployeeManagerID FROM SportEmployee WHERE DepartmentID = 1), 30/6/2008, 7158889999, 'lee.jpg', 0.05, 1,'leej', '1j2k3k')

  4. #4
    Join Date
    Nov 2003
    Location
    Portland, OR
    Posts
    8,387
    Oh, yeah, you can't do that. :-) Why not run the SELECT query separately and save the result in a variable, then pass it to the INSERT statement along with the other values?
    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
    Jan 2006
    Posts
    67
    Thanks

Similar Threads

  1. how to clone database using mysql
    By zarien in forum Database
    Replies: 1
    Last Post: 05-17-2006, 04:27 AM
  2. Java INSERT statement
    By shuStudent in forum Java
    Replies: 1
    Last Post: 04-18-2005, 11:34 AM
  3. Insert statement
    By Nimisha in forum Database
    Replies: 2
    Last Post: 04-09-2003, 10:54 AM
  4. Replies: 1
    Last Post: 04-24-2002, 09:08 PM
  5. SQL Tutorial (Answer Q's & post your reply)
    By bigbastard4 in forum Database
    Replies: 2
    Last Post: 05-16-2001, 07:24 PM

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


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center