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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Update help

Status
Not open for further replies.

Bell1991

Programmer
Aug 20, 2003
386
US
I need to update a table.. but i am not sure how to do it..

I want to:
Update tblTableName
set dtStartDate = b.dtStartDate,
txtClass = b.txtClass,
txtCourseNumber b.txtCourseNumber,
txtCourseName = b.txtCourseName
from tblTable -- This is where i don't know what to do..

The record i want to to update is:
Select top1 max(dtStartDate), txtClass, txtCourseNumber, txtCourseName from tblHistoryTable
group by dtStartDate, txtClass, txtCourseNumber, txtCourseName

The tables are related based on a column called numClassID.

Any suggestions would be greatly appreciated..

 
Hi,

If you're linking the two tables with NumClassID, you'll need to update your derived table to return this id.

If I understand your question correctly, your SQL can look something like this...

Code:
UPDATE t
SET t.dtStartDate = b.dtStartDate,
    t.txtClass = b.txtClass,
    t.txtCourseNumber b.txtCourseNumber,
    t.txtCourseName = b.txtCourseName
FROM tblTableName AS t
JOIN ([Derived Table]) as b on t.NumClassId = b.NumClassID

Ryan
 
That is exactly what i am looking for..

Thank you so much!

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top