tags:

views:

111

answers:

3

I want to do the following:

I have a table called Name which has an ID field.

I have another blank table called Transcript

I want to take the ID#s from Name and insert them into Transcript where they do not exist.

Secondly I want to create 10 records with a different COURSE# value in the Transcript table.

Therefore for each Name.ID I would like 10 records in Transcript.ID with a different value under course # ie; 101,201,301

+1  A: 

Something like this might work:

INSERT INTO TableB

SELECT TableA.id FROM TableA
LEFT OUTER JOIN TableB
ON TableA.name = TableB.name
WHERE TableB.id IS null
Abe Miessler
A: 

Another query that will return the same thing

INSERT INTO TABLEB SELECT TableA.ID FROm TableA WHERE ID NOT IN (SELECT Id FROM TableB)

David Brunelle
Mines faster ;)
Abe Miessler
Most likely, but I wanted to show that there is more than one solution :) .I did up vote you by the way :p
David Brunelle
A: 

Assuming that you are getting your course numbers from some outside courses table, here is the t-sql:

INSERT INTO transcript (name_id, course_id)
SELECT n.name_id, c.course_id
FROM name n 
CROSS APPLY courses c
WHERE n.last_name = 'xxx'

This will insert all of the courses in the table for all of the names found by the where clause.

Keith Rousseau