Monday, February 7, 2011

Previous Month Count in SP

CREATE PROCEDURE [dbo].[SP_NAME]

AS
BEGIN

select FieldName,count(FieldName)as alias from tablename
where fielddate>= DATEADD(month, DATEDIFF(month, 0, getdate()) - 1, 0)
AND dt < DATEADD(month, DATEDIFF(month, 0, getdate()), 0)
group by FieldName
 HAVING COUNT(FieldName) >= 1
 ORDER BY FieldName ASC
END

No comments:

Post a Comment