I have developed a pretty complicated query, and now have hard time modifying it to use INSERT INTO statement.
The query (VS syntax):
@"SELECT s.TagID, se.SessionID, " +
" @todaysDate " +
" AS ScanningTime " +
" FROM (((Student s " +
" LEFT JOIN [CourseID-ModuleID] cm ON s.CourseID = cm.CourseID) " +
" LEFT JOIN [ModuleID-SessionID] ms ON cm.ModuleID = ms.ModuleID) " +
" LEFT JOIN [Session] se ON ms.SessionID = se.SessionID) " +
" WHERE s.TagID = @tagNo " +
" AND se.SessionDate = cast(getdate() as date) " +
" AND se.SessionTimeStart <= @Plus30Min " +
" AND se.SessionTimeEnd >= @Plus30Min ";
The query runs perfectly, but I would like to place the result of the query into the empty table Attendance, which already exists in the DB.
Attendance table data types
TagID - int
SessionID - varchar
ScanningTime - datetime.
Please note that data types for Attendance table match with other tables data types.
I have tried placing "INSERT INTO Attendance (s.TagID, se.SessionID, ScanningTime)" just before the SELECT statement, but then my query does not produce any results.
What is a proper way to modify my query to include INSERT INTO statement? Thanks
EDIT:
All your answers and suggestions where very helpful. Thank you!
INSERT INTO Attendance (TagID, SessionID, ScanningTime)