Skip to content
Advertisement

If today is friday then extract data 7 to 9 days from today, if not 7 days

If today is Friday, I would like to get data 7 to 9 days from now, if not 7 days. I am using SQL Server.

Before:

id class startdate
1 English 2020-12-21 00:00:00.000
2 English 2020-12-22 00:00:00.000
3 Math 2020-12-21 00:00:00.000
4 English 2020-12-27 00:00:00.000
5 Math 2020-12-27 00:00:00.000

If today is 14/12/2020 – Monday, it will produce the result below:

id class startdate
1 English 2020-12-21 00:00:00.000
3 Math 2020-12-21 00:00:00.000

I tried the following, but it doesn’t work.

Advertisement

Answer

You can’t use a CASE expression like this in SQL Server. Try this instead:

Demo here

To answer to your comment:

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