In SQL Server you can use YEAR
, MONTH
and DAY
instead of DATEPART
.
(at least in SQL Server 2005/2008, I’m not sure about SQL Server 2000 and older)
I prefer using these “short forms” because to me, YEAR(getdate())
is shorter to type and better to read than DATEPART(yyyy, getdate())
.
So you could also query your table like this:
select *
from your_table
where month_column = MONTH(getdate())
and year_column = YEAR(getdate())