[link text][1]Good day, I am trying to a dd a column to our calendar tally table,with the week of the month number. I am using DENSE_RANK() OVER(PARTITION BY [ISO_Month#] ORDER BY [ISO_Week#]) AS '__Week_of_Month__'. the problem is that in some cases, the ranking starts at 2 and not 1.
I add a screencapture and test dataset in order to assist with replication of the issue.
Using SQL 2016 SP1 with CU4 on Windows 10(1703) fully updated.
![alt text][2]
==================================================
Dataset for testing:
[link text][3]
==================================================
--- My query:
SELECT
[Date]
, [Year]
, [MonthName]
, [ISO_Month#] --- The month in which the full week (Monday to Friday) reside, Decier for week is where the THursday reside as per ISO8601
, [ISO_Week#] --- The standard ISO8601 week number
, DENSE_RANK() OVER(PARTITION BY [ISO_Month#] ORDER BY [ISO_Week#]) AS '__Week_of_Month__'
, [DayName]
, [ISO_Day#]
, [OrdinalDate]
, [WeekStart]
, [WeekEnd]
, [FullWkNotation]
FROM
[cdata].[tb_ISOCalendar]
ORDER BY
[Date]
==================================================
[1]: /storage/temp/4242-denserankdata-2.zip
[2]: /storage/temp/4241-denserankissue.png
[3]: /storage/temp/4240-denserankdata.zip
↧