Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating new Table, filling it with data from other tables

Status
Not open for further replies.

vonehle

Programmer
May 16, 2006
35
US
I'm having trouble figuring out how to fill a table with data from 3 other tables. Here's a simple example...

Code:
CREATE TABLE dbo.Transcripts( StudentID int, First_Name CHAR(20), Last_Name CHAR(20),
							Semester int, ClassID CHAR(5), 
							Title CHAR(50), Grade int,
							Credits int, GPA float )

GO

INSERT INTO dbo.Transcripts(StudentID, ClassID, Grade, Semester)
	Select StudentID, ClassID, Grade, Semester FROM dbo.Enrollment
	Where Semester<>0
GO

INSERT INTO dbo.Transcripts(First_Name)
	Select First_Name from dbo.Students
	Where dbo.Transcripts.StudentID = dbo.Students.StudentID

The problem occurs on the second INSERT section. I'm trying to match the StudentID to fill in the correct name. I also tried using an UPDATE there. The error I get says "The multi-part identifier "dbo.Transcripts.StudentID" could not be bound.
 
You need to use an update statment here with a Join.. but the error is because you don't need the dbo.tablename

somehthing like:
Update Transcripts
set col = something
from Transcripts t
Inner Join Students s ON
t.StrudentID = s.StudentID
 
I'm not sure I understand how I could use the UPDATE because the SET would be different every time. Isn't SET static?

Thanks for your help. I'm going to read up on the JOIN stuff again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top