September 5, 2003 at 9:20 am
Hi,
I am trying to add the field 'OrderID' into the master list for an Insert query. How would I do that? Basically, I want the query to Insert a row using StudentID, PackageID, and OrderID as the identifiers. Here is the current code:
Insert into nStudentExams
(StudentID, ExamName, OrderID, PackageID, ForCE, Hours)
SELECT DISTINCT
dbo.nStudentCourses.StudentID,
dbo.nPackages.PackageName + ' Final Exam' AS ExamName,
dbo.nStudentCourses.OrderID,
dbo.nStudentCourses.PackageID, dbo.nStudentCourses.ForCE,
dbo.nStudentCourses.RequiredStudyTime AS Hours
FROM dbo.nStudentCourses INNER JOIN
dbo.nPackages ON
dbo.nStudentCourses.PackageID = dbo.nPackages.PackageID LEFT
OUTER JOIN
dbo.nStudentExams ON
dbo.nStudentCourses.StudentID = dbo.nStudentExams.StudentID
WHERE (dbo.nStudentExams.ExamID IS NULL) AND
(NOT (dbo.nStudentCourses.PackageID IS NULL)) AND
(dbo.nPackages.HasFinal = 1)
Thanks in advance!
September 5, 2003 at 11:46 am
September 5, 2003 at 12:17 pm
The query runs fine. What I'm trying to do is have 'OrderID' be one of the fields the query looks for within the FROM clause. For example, I want to Insert all the rows within the database that have the same 'StudentID', 'PackageID', and 'OrderID'. I tried to add 'OrderID' from the LEFT INNER JOIN, but it gave me an error message. 'OrderID' is within the nStudentCourses table or Orders table.
Thanks.
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply