Dynamic Where variable

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

  1. #1

    Default Dynamic Where variable

    I'm attempting to create a complete "Where" statement and save it to a variable.
    It works fine when comparing a numeric field against a number but errors when
    comparing a text field with text.

    Using MS Access and CF7.

    Suggestions please.



    This code works.
    <cfset where_variable = "where people.id =" 1>

    <cfquery name="staff" datasource="company">
    SELECT people.*
    FROM people
    #where_variable#
    </cfquery>

    This code doesn't
    <cfset where_variable = "where people.first_name = 'bob' ">

    <cfquery name="staff" datasource="company">
    SELECT people.*
    FROM people
    #where_variable#
    </cfquery>

    web-eng Guest

  2. Similar Questions and Discussions

    1. Dynamic number of variable
      Hello, I have a visual c++ application that puts data(variables) into a txt file, and every time it runs, it puts a different number of variables...
    2. Dynamic Variable ... how can I ?
      Hi ! I need to disabled some buttons. Here's some AWEFUL code I have : for (i=1996; i<=2004; i++) { if (_root.year_array == false) { if...
    3. Dynamic Text Variable
      Yes. Set up a field so that a script will change whatever variable the dynamic text field is linked to.
    4. evaluating dynamic variable
      Hi, I'm having trouble evaluating a dynamic variable. I want to check if the variable $_POST is an empty string, as you'll see from the code....
    5. Dynamic variable assignments
      Here is a code segment for a frames page. I want to be able to change a frame source page depending on the browser. This is what I tried but it...
  3. #2

    Default Re: Dynamic Where variable

    web-eng wrote:
    > <cfquery name="staff" datasource="company">
    > SELECT people.*
    > FROM people
    #preserveSingleQuotes(where_variable)#
    > </cfquery>
    PaulH *TMM* Guest

  4. #3

    Default Re: Dynamic Where variable

    Thanks Paul,

    works a treat.

    :)
    web-eng Guest

  5. #4

    Default Re: Dynamic Where variable

    I know that solved ur error, but I tried using that and it doesnt work for me

    <cfset lineaSQL = lineaSQL & " AND Usuario.sexo = '" & formulario.sexo & "'">

    WHERE #PreserveSingleQuotes(lineaSQL)#

    Trows an error

    Error Executing Database Query.
    [Macromedia][SQLServer JDBC Driver][SQLServer]Invalid column name 'm'

    that "m" is the data of that formulario.sexo variable

    raulriera Guest

  6. #5

    Default Re: Dynamic Where variable

    Try <cfset lineaSQL = lineaSQL & " AND Usuario.sexo = " '#formulario.sexo#' >

    web-eng 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