locked
SQL Query for returning Current Month RRS feed

  • Question

  • I am trying to get a result where the only records returned have a created on date of the current month.
    Using the following query I'm getting all the records:

    SELECT

    FilteredIncident.incidentid
      ,FilteredIncident.createdon
    FROM
      FilteredIncident

    So what would the WHERE statement have to be to return only the records for the current month?
    I've tried loads of options, and none work.
    Rob


    www.crmconsult.info www.chorusit.com
    Monday, July 20, 2009 12:40 PM

Answers

  • Hi

    Try this

    SELECT
    	FilteredIncident.incidentid
       ,FilteredIncident.createdon
    FROM
      FilteredIncident
    WHERE YEAR(FilteredIncident.createdon) = YEAR(GETDATE())
     AND MONTH(FilteredIncident.createdon) = MONTH(GETDATE())



    Rajesh Jonnalagadda http://www.ggktech.com
    Monday, July 20, 2009 12:48 PM
    Answerer

All replies

  • Hi

    Try this

    SELECT
    	FilteredIncident.incidentid
       ,FilteredIncident.createdon
    FROM
      FilteredIncident
    WHERE YEAR(FilteredIncident.createdon) = YEAR(GETDATE())
     AND MONTH(FilteredIncident.createdon) = MONTH(GETDATE())



    Rajesh Jonnalagadda http://www.ggktech.com
    Monday, July 20, 2009 12:48 PM
    Answerer
  • Fantastic!
    Thanks Rajesh
    www.crmconsult.info www.chorusit.com
    Monday, July 20, 2009 12:49 PM