Using WHERE with variables.

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

  1. #1

    Default Using WHERE with variables.

    How do I format my SQL so it can select things from the database when i'm
    trying to find something in a variable with multiple values.

    In the below code, #FORM.building will end up returning several results. eg.
    CAPEN_10,CAPEN_14,CAPEN_21.
    If any of these results are in the table as "InfoSourceName" I want it to give
    me the corrosponding "ComboFall".

    <cfquery name="Recordset1" datasource="Fake_Matrix">
    SELECT InfoSourceName, ComboFall
    FROM tblRoomMatrix
    WHERE InfoSourceName IN ('#FORM.building#')
    </cfquery>

    If I make it so that #FORM.building# only has one value, and i change the SQL
    to "=" it works fine.


    mjmcevoy Guest

  2. Similar Questions and Discussions

    1. #39833 [NEW]: Session variables overwritten by local variables (register_globals=off)
      From: sup1382 at accedo dot es Operating system: OpenBSD 3.9 PHP version: 5.2.0 PHP Bug Type: Session related Bug...
    2. #39447 [NEW]: Want to optionally handle apc_upload_progress variables using session variables
      From: krudtaa at yahoo dot com Operating system: All PHP version: 5.2.0 PHP Bug Type: Feature/Change Request Bug...
    3. Global variables - application variables vs include file
      What are the best methods for using global constants and variables? I've noticed that many people put all global constants in a file and include...
    4. Replacing code based on static variables to variable variables.
      Can anyone give me some help or tips in converting this code to take 2 variables that will specify the number of Pack type lines and the number of...
    5. variables that change session variables
      Hi, I'm currently writing a mulit-page form app that uses a session to retain data from each form element in order for the user to jump between...
  3. #2

    Default Re: Using WHERE with variables.

    IN clause is similar to =, =>, between, etc. in that if it's a text field the
    values must be in quotes (with a comma separator), whereas if they're Dates or
    Numbers you don't use quotes. You could build a loop to add the quotes
    yourself or the ListQualify function will do it for you. Be aware that ALL
    list functions ignore nulls, A,B,C,,D,,E has 4 elements not 6.

    Finally, whichever method you chose, you will need the PreserveSingleQuotes
    function so that your quotes don't get doubled up.

    WHERE InfoSourceName IN (#PreserveSingleQuotes(myNewListWithQuotesAdded)#)



    JMGibson3 Guest

  4. #3

    Default Re: Using WHERE with variables.

    Originally posted by: mjmcevoy
    I'm sorry, don't know how I that is done. If you have time could you go a
    little more in depth. Thank you.

    Change this
    WHERE InfoSourceName IN ('#FORM.building#')
    to this
    WHERE InfoSourceName IN (#listqualify(FORM.building)#)

    Details are in the cfml reference library. If you don't have one, the
    internet does.


    Dan Bracuk Guest

  5. #4

    Default Re: Using WHERE with variables.

    Many thanks to both of you.
    mjmcevoy 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