You didn’t give too many details, I think what you need is something like this:
SELECT SearchId, getdate() as CreateDate FROM Security.Search
WHERE DATEDIFF(DAY, CreateDate, GETDATE()) < 8 AND DATEPART(DW, CreateDate) != 7
I put in the Github for future reference.
This will take the last seven days but disregard Sunday. If you want to take 7 days in total already disregarding Sunday on account, then change the condition < 8
for <= 8
.
The first part of the condition takes the number of days you want (DATEDIFF
and GETDATE
) and the second part filters Sunday, which is considered the 7th day of the week obtained by the function DATEPART
.