I am need to create a table on MS SQL 2014 showing a date and a weekday column. It need to start at 2014-01-01 and the last day should be today. It should look like the one bellow:
days_date weekday
2014-01-01 Wednesday
2014-01-02 Thursday
2014-01-03 Friday
... ...
2018-03-06 Tuesday
My relevant script is here:
CREATE TABLE [dbo].[new_table](
[days_date] [date] NOT NULL,
[weekday] [nvarchar](50) NULL
) ON [PRIMARY]
GO
WITH CTE (DT) AS
(
SELECT CAST('2014-01-01' AS DATE) DT
UNION ALL
SELECT DATEADD(DAY, 1, DT)
FROM CTE
WHERE DATEADD(DAY, 1, DT) < '2018-03-06'
)
INSERT INTO [dbo].[new_table]
([days_date]
,[weekday])
VALUES
(select * from CTE,
,select DATENAME(CTE,GETDATE()))
GO
Getting some errors here:
Msg 156, Level 15, State 1, Line 13
Incorrect syntax near the keyword 'select'.
Msg 156, Level 15, State 1, Line 14
Incorrect syntax near the keyword 'SELECT'.
Msg 155, Level 15, State 1, Line 14
'CTE' is not a recognized datename option.
How should I fix the script?