79193109

Date: 2024-11-15 16:03:33
Score: 3
Natty:
Report link

In case it helps someone, this is is a recursive CTE solution that I needed recently:

DECLARE @PayCalendarStartDate DATE = '2024-01-01'; DECLARE @PayCalendarEndDate DATE = '2024-12-31';

WITH PayCalendar AS ( SELECT PayPeriodStartDate = @PayCalendarStartDate , PayPeriodEndDate = DATEADD (DAY, 13, @PayCalendarStartDate) UNION ALL SELECT PayPeriodStartDate = DATEADD (DAY, 14, PayCalendar.PayPeriodStartDate) , PayPeriodEndDate = DATEADD (DAY, 14, PayCalendar.PayPeriodEndDate) FROM PayCalendar WHERE PayPeriodEndDate <= @PayCalendarEndDate ) SELECT * FROM PayCalendar;

Reasons:
  • Blacklisted phrase (0.5): I need
  • Long answer (-0.5):
  • No code block (0.5):
  • Unregistered user (0.5):
  • User mentioned (1): @PayCalendarStartDate
  • User mentioned (0): @PayCalendarEndDate
  • User mentioned (0): @PayCalendarStartDate
  • User mentioned (0): @PayCalendarStartDate
  • User mentioned (0): @PayCalendarEndDate
  • Low reputation (1):
Posted by: glennvw