Query - Datediff problem

Ask a Question related to Coldfusion Database Access, Design and Development.

  1. #1

    Default Query - Datediff problem

    Hello all,

    I am trying to generate a list of users that have not responded to a survey in
    3 months, but I am running into problems with the query...

    I am using Access and here is my query...

    <cfquery name="get_people" datasource="#Application.dsn#">
    SELECT *
    FROM contact
    WHERE survey_type = 2
    AND #dateDiff("m", Now(), datelast_responded)# <= 3
    ORDER BY lname ASC
    </cfquery>


    I get the error [Macromedia][SequeLink JDBC Driver][ODBC
    Socket][Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 1.

    What am I doing wrong??

    Niles Runeberg Guest

  2. Similar Questions and Discussions

    1. Datediff() bug
      The Datediff("m",startdate,enddate) function does not return the correct value if the startdate is "2/28/05" and the enddate has a day value of...
    2. Datediff Problem
      I am having some difficulties with the function Datediff! I am trying to calculate the number of days between two given date E.G: Number days...
    3. DateDiff Problem with the Year 2000
      I am having a problem calculating the proper age of people if they were born in the year 2000 <cfset bydate=#dateformat(#todaydate#,"mm/dd/yy")#>...
    4. DateDiff problem on different servers
      I have an ASP page that lists files and folders in a directory. I'm using a cookie to record the last time this page was visited, and I intend to...
    5. Using DatePart and DateDiff together in a query
      Does any one know how I would go about using DatePArt and DateDiff in the same query for the same field? For example, I need to get the amount of...
  3. #2

    Default Re: Query - Datediff problem

    Try pulling the DateDiff function out of the WHERE clause and assign it to a
    variable. Use that variable in your WHERE. If the problem is in the DateDiff
    function, the error will be thrown on the assignment.

    jdeline Guest

  4. #3

    Default Re: Query - Datediff problem

    WHERE survey_type = 2 AND DateDiff('m', Now(), datelast_responded) <= 3

    HTH
    --
    Tim Carley
    [url]www.recfusion.com[/url]
    [email]info@NOSPAMINGrecfusion.com[/email]
    Mountain Lover Guest

  5. #4

    Default Re: Query - Datediff problem

    Originally posted by: jdeline
    Try pulling the DateDiff function out of the WHERE clause and assign it to a
    variable. Use that variable in your WHERE. If the problem is in the DateDiff
    function, the error will be thrown on the assignment.

    But that would require another query wouldn't it? The variable
    datelast_responded is coming right from the database...



    Niles Runeberg Guest

  6. #5

    Default Re: Query - Datediff problem

    That doesn't work either... it doesn't limit the dates properly, the output has
    an entry from today in there which means the datediff did not work.

    I can use a cfif later down the page to filter the results, but that is not
    good code.

    Niles Runeberg Guest

  7. #6

    Default Re: Query - Datediff problem

    What?
    A datediff <= 3 months ('m') is going to include today, especially since
    you are using Now(). Why would you think it should not?


    --
    Tim Carley
    [url]www.recfusion.com[/url]
    [email]info@NOSPAMINGrecfusion.com[/email]
    Mountain Lover Guest

  8. #7

    Default Re: Query - Datediff problem

    If you don't want today, then you will need to use days ('y') and maybe
    even Now()-1 and then test for <= 90

    HTH

    --
    Tim Carley
    [url]www.recfusion.com[/url]
    [email]info@NOSPAMINGrecfusion.com[/email]
    Mountain Lover Guest

  9. #8

    Default Re: Query - Datediff problem

    Niles,

    Are you trying to retrieve a list of users that last responded to a survey
    over three months ago? So if today is 08/19/2005, you want people that last
    responded prior to 05/20/2005? Sssuming your date column contains only a date
    and not a date and time (ex. '2005-05-19 13:57:46'), you try something like the
    query below. You may also want to check for null dates, to find users that
    never responded at all.



    ---- example
    SELECT (SomeColumns)
    FROM contact
    WHERE survey_type = 2
    AND datelast_responded <= #CreateODBCDate(dateAdd("m", -3, now()))#
    ORDER BY lname ASC

    <!--- the query above translates to
    ......
    WHERE survey_type = 2 AND datelast_responded <= {d '2005-05-19'}
    --->

    mxstu Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139