Reputation: 43
This is my current SQL Select query;
SELECT
Name AS 'Class Name', FirstName + ' ' + LastName AS 'Instructor',
LessonDuration AS 'Lesson Duration (hrs)', LessonTime AS 'Lesson Start'
FROM
Lesson, Class, Instructor
WHERE
Lesson.ClassID = Class.ClassID
AND Lesson.InstructorID = Instructor.InstructorID
AND LessonDay = 'Monday'
ORDER BY
LessonTime ASC;
I have a table Lesson
with some columns, but most importantly LessonDuration
(in hours) and LessonTime
(which is the start time). In a select query, I would like to have an additional column that displays the end time. This would involve calculating the additional hours put onto the start time using the duration but I am unsure how to do so.
I am using SQL Server built into Visual Studio 2013.
Upvotes: 0
Views: 862
Reputation: 13393
You can use this.
SELECT Name AS 'Class Name', FirstName + ' ' + LastName AS 'Instructor',
LessonDuration AS 'Lesson Duration (hrs)', LessonTime AS 'Lesson Start' , DATEADD(HOUR,LessonDuration,LessonTime) 'End Time'
FROM Lesson, Class, Instructor
WHERE Lesson.ClassID = Class.ClassID
AND Lesson.InstructorID = Instructor.InstructorID
AND LessonDay = 'Monday'
ORDER BY LessonTime ASC;
Upvotes: 1