Loop through date in SQL Server and exclude the dates within a range of one week

44 Views Asked by At

I have a set of data where I want to loop through them and if I have dates within a range of one week (7 days) i want to only count the first 1 of them.

Please see below table.

For example, for customer Bell, the date 10/25/2023 should be excluded or flagged as 0, because there is a date for Bell in 10/22/2023 and only 3 days between them.

I have this dataset in a table in SQL and I'm not familiar on how to do it in SQL Server.

Thank you and appreciate the help.

enter image description here

0

There are 0 best solutions below