Skip to main content
Inspiring
April 25, 2006
Answered

help with query

  • April 25, 2006
  • 2 replies
  • 288 views
This has got to be easy but I'm just not getting there.

Simply put I want to query a db with the field name "completed". Completed is a date field (mm/dd/yyyy/). I want the query to return results where the instructed year matches the yyyy part of the completed field.

For simplicity sake, lets set the instructed year to be the current year ( <cfset nowYear=#year(now())#> )
    This topic is closed to new replies. Start a new post to keep the conversation going.
    Correct answer jkgiven
    yep, that took care of it - Thanks!

    2 replies

    Inspiring
    April 25, 2006
    Depends on the database you're using.

    <cfquery name="MyQuery" datasource="Sfkgj">
    SELECT *
    FROM table
    WHERE Year(completed) = <cfqueryparam value="#nowYear#" cfsqltype="CF_SQL_INTEGER"/>
    </cfquery>

    ...should work with MySQL and Access.
    Other databases may work the same, or might require something similar to DatePart(completed,'yyyy')
    jkgivenAuthorCorrect answer
    Inspiring
    April 25, 2006
    yep, that took care of it - Thanks!