Setting a SQL Statement as a Variable and Running UsingCFQuery

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

  1. #1

    Default Setting a SQL Statement as a Variable and Running UsingCFQuery

    I've got a table with a bunch of sql statements that I need to run and cfdump
    the results to the screen. I have one <cfquery> tag that pulls the sql
    statement out of the database based on an ID number given: <cfquery
    name='retrieveSqlStatementToRun'> SELECT sql_statement as sqlData FROM Table1
    WHERE statement_id = #sqlID# </cfquery> This works fine, and when I <cfdump>
    or <cfoutput> the variable #retrieveSqlStatementToRun.sqlID# I see the SQL
    statement I want to run: SELECT First_Name, Last_Name, Birthday FROM Table2
    WHERE Last_Name = 'Smith' But when I set up the second <cfquery>, using only
    the #retrieveSqlStatementToRun.sqlID# it gives me an 'Error Executing Database
    Query' Here's the code for the second query: <cfquery name='runSqlStatement'>
    #retrieveSqlStatementToRun.sqlData# </cfquery> Is there anything special I
    need to do to run an entire SQL statment (the selects, from, and where) via one
    Cold Fusion variable? Thank you! -Ryan

    ryanstewart Guest

  2. Similar Questions and Discussions

    1. Setting a string to a conditional statement?
      I want to allow users of my website to define there own custom queries using a form. The problem that i am running into is that cfset cannot handle...
    2. Setting a variable name with a variable in a loop
      Here is the code that bombs: <cfloop index='x' from='1' to='10' step='1'> <cfif #evaluate('form.totalhours#x#')# eq 'r'> <cfset total_hours_#x# =...
    3. A variable in a php statement
      Hi This works: <?php if (isset($_GET)) { echo '<input type='hidden' name='frm_catid' value='71'>'; } else { echo '<input...
    4. variable select statement
      I would like to have a form that gives the user choices for selection parameters for email, printing etc. A real simple example: Give me all...
    5. #22558 [Com]: DB2 seems to be 10x slower than MYSQL running a simple select statement
      ID: 22558 Comment by: port at iname dot com Reported By: danl at icarz dot com Status: Bogus Bug Type: ...
  3. #2

    Default Re: Setting a SQL Statement as a Variable and RunningUsing CFQuery

    Try this:
    <cfquery name='runSqlStatement'>
    #preserveSingleQuotes(retrieveSqlStatementToRun.sq lData)#
    </cfquery>

    inside a cfquery block CF replaces ' with ', using this function prevents that.
    kyle969 Guest

  4. #3

    Default Re: Setting a SQL Statement as a Variable and RunningUsing CFQuery

    Works like a charm, thanks!
    ryanstewart 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