SQL Server DATEPART for year and month
4 answers
Should work with SQL Server 2005 and 2008
DECLARE @Date DATETIME = GETDATE();
SELECT CAST(YEAR(@Date) AS VARCHAR(4))
+ RIGHT('00' + CAST(MONTH(@Date) AS VARCHAR(2)),2)
RESULT: 201606
If you are going to use it in the where clause you can do something like ...
WHERE YEAR(DateColumn) = 2016
AND MONTH(DateColumn) = 6
+1
source to share