Search code examples
sqlsql-serverlabview

Trying to get an SQL command that gets the new customers from each month but i cant seem to get it working


I am trying to pull the new customers from each month from an SQL database. I've tried this:

SELECT COUNT (Name) 
FROM Customer 
WHERE Date_created BETWEEN CONVERT(date, getdate()) AND CONVERT(date, getdate()) - (30)

Solution

  • From your query I think this would do it simpler :

    SELECT COUNT (Name) FROM Customer WHERE MONTH(Date_created)= MONTH(GETDATE())
    

    although am not sure this is what you expect as your question could be interpreted in several ways

    Edit : taking account of different years:

    SELECT COUNT (Name) FROM Customer 
    WHERE MONTH(Date_created)= MONTH(GETDATE())
    AND YEAR(Date_created)= YEAR(GETDATE())