passing SQL in a variable

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

  1. #1

    Default 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 frm_int_interest_ind neq "">
    <cfset search_frm_int_interest_ind = "(">
    <cfloop index="el" list="#frm_int_interest_ind#">
    <cfset search_frm_int_interest_ind = "#search_frm_int_interest_ind#'#el#',">
    </cfloop>
    <cfset len_search_frm_int_interest_ind = "#len(search_frm_int_interest_ind)#">
    <cfset search_frm_int_interest_ind = "#Left(search_frm_int_interest_ind,
    evaluate(len_search_frm_int_interest_ind - 1))#">
    <cfset search_frm_int_interest_ind = "#search_frm_int_interest_ind#)">
    <!--- Now that the list is properly formatted, set up the query string --->
    <cfset queryvariables = "AE_int.int_interest_ind
    in#search_frm_int_interest_ind#">
    </cfif>
    <cfquery name="Entrepreneur_Int_search" datasource="#AlumDS#">
    SELECT *
    FROM Alumni A JOIN Alumni_Entrepreneur_Int AE_int
    On A.User_Login = AE_int.User_Login
    Where
    #queryvariables#
    </cfquery>

    The error that gets returned is: Diagnostics: ODBC Error Code = 37000 (Syntax
    error or access violation)

    Line 6: Incorrect syntax near '1'.

    The cfdump (and cfoutput) of #queryvariables# is:
    AE_int.int_interest_ind
    in('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')
    which I can cut and copy into the cfquery tag and execute just fine.

    I assume something is wrong with the #queryvariables# format, but trying
    evaluate or de has not worked.

    Also, if there is a more elegant way to handle building the sql, I'd
    appreciate the suggestion(s).

    Thanks,

    Chris

    Beards247 Guest

  2. Similar Questions and Discussions

    1. Passing a variable to asp
      I cannot work out how to get the variable namefirst from flash to the asp I use : ...
    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 second value in a variable
      Two or querysting variables can be passed by separateing them with an ampersand: page.asp?p1=1&p2=2 HTH, Bob Barrows Raphael Gluck wrote:
    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 SQL in a variable

    The PreserveSingleQuotes function will probably work.
    Dan Bracuk Guest

  4. #3

    Default Re: passing SQL in a variable

    That is exactly what I was looking for! Thank you!
    Beards247 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