I am trying to create a table with two columns, holiday_date and day_of_the_week.
I'd like the day_of_the_week column to be derived by default from the holiday_date column using the datepart() function. The day_of_the_week column is by default null and computed when new values of holiday_date are inserted.
I have tried using the query below:
CREATE TABLE [HolidaysTest] (
[holiday_date] varchar(50),
[day_of_the_week] int DEFAULT datepart(dW, holiday_date)
)
This isn't working and the error that results is shown below
The name "holiday_date" is not permitted in this context. Valid expressions are constants, constant expressions, and (in some contexts) variables. Column names are not permitted.