-
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 09:05 PM.
-
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!
-
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')
-
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!
-
Similar Threads
-
By zarien in forum Database
Replies: 1
Last Post: 05-17-2006, 03:27 AM
-
By shuStudent in forum Java
Replies: 1
Last Post: 04-18-2005, 10:34 AM
-
By Nimisha in forum Database
Replies: 2
Last Post: 04-09-2003, 09:54 AM
-
By Nitin in forum ASP.NET
Replies: 1
Last Post: 04-24-2002, 08:08 PM
-
By bigbastard4 in forum Database
Replies: 2
Last Post: 05-16-2001, 06: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
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