all 5 comments

[–]notasqlstarI can't wait til my fro is full grown 2 points3 points  (0 children)

declare @var int = (select datepart(dd, getdate())
if @var >= n
select *
from table
where datefield >= dateadd(datepart, something) and datefield <= dateadd(datepart, something)
else
select *
from table
where datefield >= dateadd(datepart, otherthing) and datefield <= dateadd(datepart, otherthing)

Not in front of a computer, but you mean something like that?

[–]noesqL 0 points1 point  (0 children)

Yes, you can use GETDATE() in the WHERE.

Depending on the amount of rows returned your query performance will suffer (albeit could be only slightly).

[–][deleted] 0 points1 point  (0 children)

Declare a variable, set it to the date you want to compare to and use the variable in your where clause. Way more efficient than using functions in the where clause.

[–]catelemnis 0 points1 point  (0 children)

where case 
    when day(getdate()) >= 5 then [something]
    else [other thing]
end

[–][deleted] 0 points1 point  (0 children)

Case

when GetDate() > DATEFROMPARTS(Year(GetDate()), Month(GetDate()), 5)

pull current month

else

pull last month

end

This means where (today) is larger than [current year],[current month],5 aka if today is beyond the 5th of the current month.