Queried variable 'undefined'

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

  1. #1

    Default Queried variable 'undefined'

    Hello All,

    There seems to be a problem with the following query: If I remove the WHERE
    clause, all records are returned and properly formatted later in the page.
    However, with the WHERE clause present, CF returns an error stating that
    EventSchedDate is undefined.

    The terribly convoluted equation is for the creation of a sort of numerical
    'absolute' date (like a Julian Date) and may very well be what is causing the
    problem, but I can't see how.

    Furthermore, the same equation is being used in the output of the query later
    in the page for testing purposes as the results are correct.

    Could there be an issue with actually performing certain functions within the
    WHERE clause?

    I'll get the coffee ready...

    Thanks,
    Robert Nicholas



    <cfquery name="getEvents" datasource="#DataSource#">
    SELECT EventName, EventSchedDate, EventDesc, EventFee
    FROM tblEventSchedule
    WHERE '#dFirst#' <=
    '#(w-2)*7+dayofweek(EventSchedDate)+3+(year(EventSchedD ate)-2001)*365#'
    AND '#(w-2)*7+dayofweek(EventSchedDate)+3+(year(EventSchedD ate)-2001)*365#'
    <= '#dLast#'
    </cfquery>

    crux_online Guest

  2. Similar Questions and Discussions

    1. Session variable is undefined
      I have a frame structure site. In main application.cfm I define session variable <cflock timeout='20' scope='Session' type='exclusive'> <cfif...
    2. Undefined variable in my search
      I have two cfquerys that work off a search form where I have just one input field on the search form. I wanted this so I can get seperate Table...
    3. Undefined Variable
      Can anyone tell me what's wrong with my code? I tried to create a form in html and redirect it to php. but result said: Notice: Undefined...
    4. variable undefined
      we have this variable from the internet, val(0), in a dynamic text field we can see a digit from this variable. but when we use this variable in...
    5. [PHP] undefined variable
      did you solve this problem? i checked the coding in my linux box, it's working fine. Viraj Chris Kay wrote:
  3. #2

    Default Re: Queried variable 'undefined'

    You're using the table field "EventSchedDate" in a ColdFusion output section
    (delimited with the pound signs). This doesn't work. You have to use a value
    that CF understands in the context of the template in which you're running this
    query. That is, "EventSchedDate" must be a ColdFusion variable in any of the
    scopes available to the template for you to employ it between the pound signs.

    Or, you can use native database functions and syntax to replace what you're
    doing with ColdFusion functions in the WHERE clause.

    philh Guest

  4. #3

    Default Re: Queried variable 'undefined'

    You need to get rid of the single quotes around your field names in your WHERE
    clause. And take the calculations out of the WHERE clause and create a
    variable in its place. See code below.

    Do the variables dFirst and dLast contain a field name? Are the literal
    strings dFirst and dLast field names? Whatever, the proper syntax for your
    WHERE clause is :

    fieldname1 op value1 AND fieldname2 op value2

    <CFSET whereValue =
    (w-2)*7+dayofweek(EventSchedDate)+3+(year(EventSchedD ate)-2001)*365>

    WHERE fieldname1<= '#whereValue#' AND fieldname2 <= '#whereValue#'

    jdeline Guest

  5. #4

    Default Re: Queried variable 'undefined'

    Originally posted by: jdeline
    You need to get rid of the single quotes around your field names in your WHERE
    clause. And take the calculations out of the WHERE clause and create a
    variable in its place. See code below.

    Do the variables dFirst and dLast contain a field name? Are the literal
    strings dFirst and dLast field names? Whatever, the proper syntax for your
    WHERE clause is :

    fieldname1 op value1 AND fieldname2 op value2

    **********************

    That being the case, I've tried to rework it.

    dFirst and dLast are variables that are set using CFSET at the beginning of
    the page and represent the Julian-type Dates I wrote of earlier.

    Given is the new code fragment containing the query, but now I get a 'missing
    operator' error. Now, when I think 'operator', I think '=', '>', etc., and
    I've tried those as well (I'm now attempting to use LT, GT, and so on).
    Clearly that is not the problem; there is an underlying failure on my part to
    understand the required syntax.

    Thanks again,

    Robert Nicholas


    THE ERROR:

    [MERANT][SequeLink JDBC Driver][ODBC Socket][Microsoft][ODBC Microsoft Access
    Driver] Syntax error (missing operator) in query expression 'EventSchedDate GT
    '{ts '2005-11-06 00:00:00'}' AND EventSchedDate LT '{ts '2005-12-10
    00:00:00'}''.

    THE CODE:

    <cfquery name="getEvents" datasource="#DataSource#">
    SELECT EventName, EventSchedDate, EventDesc, EventFee
    FROM tblEventSchedule
    WHERE EventSchedDate GT '#CreateDate(y,m,day(dFirst))#'
    AND EventSchedDate LT '#CreateDate(y,m+1,day(dLast))#'
    </cfquery>

    crux_online Guest

  6. #5

    Default Re: Queried variable 'undefined'

    <cfquery name="getEvents" datasource="#DataSource#">
    SELECT EventName, EventSchedDate, EventDesc, EventFee
    FROM tblEventSchedule
    WHERE EventSchedDate > '#CreateODBCDate(CreateDate(y,m,day(dFirst)))#'
    AND EventSchedDate < '#CreateODBCDate(CreateDate(y,m+1,day(dLast)))#'
    </cfquery>

    Kronin555 Guest

  7. #6

    Default Re: Queried variable 'undefined'

    Originally posted by: Kronin555
    <cfquery name="getEvents" datasource="#DataSource#">
    SELECT EventName, EventSchedDate, EventDesc, EventFee
    FROM tblEventSchedule
    WHERE EventSchedDate > '#CreateODBCDate(CreateDate(y,m,day(dFirst)))#'
    AND EventSchedDate < '#CreateODBCDate(CreateDate(y,m+1,day(dLast)))#'
    </cfquery>

    Nope, same error. It's really quite puzzling, don't you think?

    Robert

    crux_online Guest

  8. #7

    Default Re: Queried variable 'undefined'

    Which "same error"?

    Missing operand? or undefined variable?
    Kronin555 Guest

  9. #8

    Default Re: Queried variable 'undefined'

    Missing Operator. Definitely a missing operator.

    Under what condition might this show up, beyond the obvious?

    Thanks
    Robert Nichlas
    crux_online Guest

  10. #9

    Default Re: Queried variable 'undefined'

    You might want to remove the single quotes from around the
    '#CreateODBCDate(CreateDate(y,m,day(dFirst)))#' statements, since I am assuming
    that EventSchedDate is a date/time object and not varchar/character.

    Phil

    paross1 Guest

  11. #10

    Default Re: Queried variable 'undefined'

    Thanks to you all for your suggestions, they all got me incrementally to the
    point where no errors occur. Too bad there are few 'affordable' references to
    which one can quickly refer.

    Thanks again, everyone. Now the real work begins.

    Robert Nicholas

    crux_online 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