Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 Script Library
 Create Derived Column

Author  Topic 

aademeo
Starting Member

5 Posts

Posted - 2014-09-16 : 20:46:19
I'm working on creating a table in SQL where one of the columns is a derived attribute. Need to declare an attribute called CourseDurationYears, which is derived by the total number of years since the CourseStartDate.

Student_Courses
StudentCoursesID
StudentID
CourseID
CourseStartDate
CourseComplete

CourseList
CourseID
CourseDescription
CourseCost
CourseDurationYears
Notes

Below is what I have so far, but I'm stuck on the CourseDurationYears. Not sure what to declare as the datatype or how to correctly have it reflect the derived value:

CREATE TABLE Student_Courses
(
StudentCoursesID INT NOT NULL IDENTITY(1,1),
StudentID INT NOT NULL,
CourseID INT NOT NULL,
CourseStartDate DATETIME NOT NULL,
CourseComplete DATETIME NULL
);

CREATE TABLE CourseList
(
CourseID INT NOT NULL IDENTITY(1,1),
CourseDescription VARCHAR(255) NOT NULL,
CourseCost MONEY NOT NULL,
CourseDurationYears DateTime(YYYY) NOT NULL,
Notes NTEXT NULL
);

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2014-09-16 : 20:51:37
Why is the CourseDurationYears in CourseList table is depend on the CourseStartDate of Student_Courses ?




KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page
   

- Advertisement -