Convert date yyyy-mm-dd to integer YYYYMM
On version 2012 or higher you can use the format
function to get just year and month, then cast it as an int.
On versions prior to 2012 you can do the formatting with the convert
function, then cast as int.
declare @dateb datetime
set @dateb = getdate()
select cast(format(@dateb,'yyyyMM') as int) --2012 or higher
select cast(convert(varchar(6),@dateb,112) as int) -- all versions
Perhaps a bit tidier:
SELECT YEAR(@dateb)*100 + MONTH(@dateb);