SELECT LoginId, FORMAT(CreationDate,'yyyy-MM') AS LoginMonth, COUNT(LoginId) AS LoginCount FROM AdayLogDB WITH(NOLOCK) WHERE LoginId=14796907 AND CreationDate>'2020-01-01' AND CreationDate<='2020-12-30' GROUP BY LoginId,FORMAT(CreationDate,'yyyy-MM')