Passing a variable to a query

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

  1. #1

    Default Passing a variable to a query

    <cfset ctr=1>
    <cfloop list="#query1#" index = "i" delimiters = ",">
    <cfset thisColumn = "subcat_"&#ctr#>
    <cfquery name="insertNodes" datasource="#dsn#">
    INSERT into maintank
    (.....)value('#i#')
    </cfquery>
    <cfset ctr=ctr+1>
    </cfloop>

    keep getting "subcat_1 does not exist".
    evaluate()? - ThankYou

    xSist Guest

  2. Similar Questions and Discussions

    1. passing SQL in a variable
      In a nutshell, user selects a bunch of radio buttons to search. On the next page, I try to put that information into queryable form: <cfif...
    2. URL Variable Passing
      First off, a disclaimer - I'm new to Cold Fusion and not well versed in all that it is capable of. I am trying to use a <cfformitem> tag to put an...
    3. passing variable
      Hello, Hopefully somebody can assist my with my issue. Basically I have simply form the asks users for the registration number, security word,...
    4. Passing a variable to a URL
      Hello, I want to have an input field that writes to, say, "input1" input at the beginning of the movie, and then all hyperlinks clicked on from...
    5. passing javascript variable into asp variable using vbscript
      The subject pretty much sums up what I need to do. Here is what I have so far, but still can't figure out how to get it working: <script...
  3. #2

    Default Re: Passing a variable to a query

    I see where subcat_1 is constructed; where is it (or thisColumn) used?
    jdeline Guest

  4. #3

    Default Re: Passing a variable to a query

    Please post the error that you're getting. I'm curious if it's a CF error complaining that a variable doesn't exist or a SQL error complaining that a column doesn't exist.
    JaredJBlackburn Guest

  5. #4

    Default Re: Passing a variable to a query

    .... clarifying, sorry

    if I use
    <cfquery ...
    (#evaluate(thisColumn)#)value('#i#')

    I get the error : "Variable subcat_1 is undefined. "

    using :
    <cfquery ...
    (#thisColumn#)value('#i#')

    I get the error : " Error Executing Database Query. Syntax error in INSERT
    INTO statement. "
    ThanYou

    xSist Guest

  6. #5

    Default Re: Passing a variable to a query

    .... found and duly noted. It should be:
    INSERT into maintank
    (#Evaluate("subcat_#i#")#)value('#i#')

    BUT

    #i# should be one of the elements of the list
    "1036592|Apparel & Accessories,1036682|Departments"
    comma delimited
    and I get the error: "Invalid token '|' found on line ..."
    It looks like a CF error ...






    xSist Guest

  7. #6

    Default Re: Passing a variable to a query

    When you use (#evaluate(thisColumn)#)value('#i#'), CF is concatinating the
    strings 'thisColumn' and '1' and then trying to evaluate the resulting string
    'thisColumn1' as if it were a CF variable. Since you have no CF variable by
    that name, it's giving you an error.

    The second way appears to be closer to what you want. Here, the CF server
    isn't crashing, but the SQL server is returning an error when it tries to
    handle your cfquery call. First, if you haven't already, turn on your debug
    output and see what SQL statement you're actually sending to the SQL server.
    The error message indicates that it's a syntax error which is probably just
    some type-o in the resulting SQL.

    JaredJBlackburn Guest

  8. #7

    Default Re: Passing a variable to a query

    It's values, not value.
    jdeline Guest

  9. #8

    Default Re: Passing a variable to a query

    ThankYou "jdeline" and "JaredJBlackburn".
    Got it to work, but it was much worse than what you have read.
    I swear I didn't drink and worls soccer Italy is ahead of Ghana so far.
    I am under heavy loads or full moons.
    All the best.
    ContiW

    xSist 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