Wrox Programmer Forums
Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2000 > SQL Server 2000
SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2000 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old May 4th, 2006, 12:48 PM
Registered User
Join Date: Jun 2004
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default multi-multi-multiple Insert with subquery???

Hello, experts, friends and masters.
I get into the point!

I have a huge (for me) problem.
I have some tables in a database. Lessons, Students, Teachers, Courses and AttendedLessons.
The last table (attendedLessons) has the following collumns:
I want to create an insert query which will take the courseID and the StudentID from the user and it will insert in the AttendedLessons records for all of the Lessons of this specific Course of this specific Student of a selected Teacher.

I have tried this....
insert into AttendedLessons (lessonID,CourseID,StudentID,TeacherID)
(select lessonID,CourseID,StudentID,TeacherID from

(select lessonID, CourseID from Lesson where CourseID='(anything that user gives)'),
(studentID='(anything that user gives)'),
(TeacherID='(anything that user gives)');

but Many different problems occured.

Please...... any suggestion?????

Old May 5th, 2006, 02:20 PM
Registered User
Join Date: Jun 2004
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts


Just in case that anyone is in the same position in which I was..... the Solution comes from a multiple insert-select subquery:

   cmdSelect = New SqlCommand("insert into attendedLessons (LessonID,StudentID,TeacherID,CourseID)
(select distinct lessonID, studentid, PersonID, courseid from Lesson, student, Personnel where Courseid='" & Request.QueryString("CourseID") & "' and studentID='" & ID & "' and PersonID='" & InstructorID & "')", conn)

The result will be to insert as many records the table "lesson" has with the courseID foreignKEY =Request.QueryString("CourseID") with the ID of the student and the ID of the teacher.

Similar Threads
Thread Thread Starter Forum Replies Last Post
comobox contain multi value capri C# 6 April 3rd, 2008 09:05 AM
multi threading [email protected] BOOK: ASP.NET Website Programming Problem-Design-Solution 1 February 26th, 2007 11:48 PM
Multi Installer VTfletch Need help with your homework? 0 December 18th, 2006 02:29 PM
Multi Report ...! anukagni Access 2 June 21st, 2006 01:35 AM
multi paged multiple checkboxes with same name pro kcs_chandra Classic ASP Basics 1 October 23rd, 2004 03:45 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.