我想要从SQL Server中的日期列开始的每个星期五的星期几。
到目前为止我尝试的是,
SELECT
[EntryDate] AS 'Date',
DATEPART(dw,[EntryDate]) AS 'Week' ,
CASE WHEN
DATEPART(dw,[EntryDate]) = DATEPART(dw,[EntryDate]) AND DATENAME(dw,[EntryDate]) = 'Friday'
THEN
DATENAME(dw,[EntryDate])
END AS 'DayName'
FROM [dbo].[EnergyDetails]
输出是: -
请有人关注一下。
感谢。
答案 0 :(得分:1)
请试试这个:
SELECT
Date,
DATEADD(DD,(7- DATEPART(DW,Date)),c.Date) as 'End Date',
DATENAME(DW,(DATEADD(DD,(6- DATEPART(DW,Date)),Date))) as 'DayName'
FROM TABLE_NAME;