I have a Dates table with every single date and a column called weekly, biweekly or monthly . I want to show my data as it would appear if it were scheduled
ex
id date weekly biweekly monthly
1 01/01/2020 1 0 0
2 01/02/2020 0 1 0
3 01/03/2020 0 0 1
So what I want to do essentially is if:
weekly=1 then show me the current date and the next 6 rows (So all the other information will be the same for this 6 rows but the date will change only)
BIweekly=1 then show me the current date and the next 13 rows
MONTHLY=1 then show me the current date and the next 29 rows
id date weekly biweekly monthly
1 01/01/2020 1 0 0
1 01/02/2020 1 0 0
1 01/03/2020 1 0 0
1 01/04/2020 1 0 0
1 01/05/2020 1 0 0
1 01/06/2020 1 0 0
2 01/02/2020 0 1 0
2 01/03/2020 0 1 0
2 01/04/2020 0 1 0
2 01/05/2020 0 1 0
2 01/06/2020 0 1 0
2 01/07/2020 0 1 0
2 01/08/2020 0 1 0
2 01/09/2020 0 1 0
2 01/10/2020 0 1 0
2 01/11/2020 0 1 0
2 01/12/2020 0 1 0
2 01/13/2020 0 1 0
2 01/14/2020 0 1 0
Best Answer
You can use CROSS APPLY and a CASE statement in your WHERE clause to produce the results you're after.
Setup:
Query:
You can see it working in this db<>fiddle example.