Skip to content
Advertisement

How to look if the value reoccurs in the table after current selection in SQL

I have below data table [CRA_feasibility_test]

I want to select the data based on the weekday of my date.If it is Y then want to get closest ‘Y’ i.e the day when it will be Y from the @date.

And also i want to get next

I am doing the following

Advertisement

Answer

If I understand correctly, you can try to create a calendar table for next 7 day by cte recursive, then use CROSS APPLY with values make unpivot to get Y date which is the closest day.

sqlfiddle

Result

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement