retrieve sql from database

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

  1. #1

    Default retrieve sql from database

    Our organization has alot of SQL, and we prefer to be able to store our
    application SQL in a DB; we find it easier to maintain that way.

    What I would like to do:
    <cfquery name="getstatement" datasource="#datasource#">
    SELECT code from sqlcode where name='statement1'
    </cfquery>
    <cfquery name="aQuery" datasource="#datasource#">
    #getstatement.code#
    </cfquery>

    The SQL code would be something like:
    select dept_id, name
    from departments
    where name like <cfqueryparam cfsqltype="cf_sql_varchar" value="#NameSearch#"
    maxlength="20">

    The problem I have is getting the <cfqueryparam> to evaluate in the above
    example.

    Does anyone have a solution for this problem? Note that I cannot use stored
    procedures.


    healey_mark Guest

  2. Similar Questions and Discussions

    1. unable to retrieve or display images from sql database
      Using Dreamweaver 8 and connecting to an Sql Server 2000 i am not able to display image files from the sql table. the other fields in the table are...
    2. how to retrieve swf file from database?
      i m still new in this actionscript thingy. i know how to load external .swf file from the same folder to flash when it is call by using ...
    3. Two Function Calls to a Database to Retrieve the UniqueID of Inserted Records
      Hi guys, I got the error message on Option 2 query as show. Actually, this code is from Inside ColdFusion MX boook. I just would like to know is...
    4. store and retrieve flash in and from database
      Hi all, i stored an uploaded flash-file in a MS-SQL database. Now i want to retrieve this file from my database in ASP.NET, but I don't know how to...
    5. Retrieve n records from database
      I came across a tutorial about a year ago that explained the answer I seek. Now, however, I cannot find the answer anywhere. I have a flash movie...
  3. #2

    Default Re: Search bar error

    You can try playing with the Evaluate() function but I believe you will find
    that it's not possible to execute a tag like <cfqueryparam> this way.

    If reverting to plain SQL, remember the PreserveSingleQuotes() function.

    To store SQL and still be able to use parameterized queries, you'll might
    pre-parse the SQL like so:

    Create 2 tables:
    1) Main SQL has at least these columns:
    1.a) ID
    1.b) Pre where-clause SQL text.
    1.c) Post where-clause SQL text.

    2) Parameterized Where-Clause table has at least these columns:
    2.a) ID
    2.b) FKey into table 1
    2.c) SQL column name and operator, (EG. "name = ")
    2.d) cfsqltype value
    2.e) CF variable name
    2.xxx ) Additional columns for additional attributes like maxlength.

    Using these two tables you can build a parameterized SQL call.
    Of course, fancy sub-selects, etc. could get messy.

    -- MikeR


    MikerRoo Guest

  4. #3

    Default Re: retrieve sql from database

    Thanks MikerRoo,

    I came to the same conclusion: evaluate() doesn't work. I am left with
    either a manual parsing solution (as you described), writing the SQL to a file
    and including it, or using cfobject to work with the underlying java code.

    I will give this more thought; I am mentioning my other ideas for the benefit
    of anyone else who's facing a similar problem.


    healey_mark Guest

  5. #4

    Default Re: retrieve sql from database

    Hey healey_mark,

    It looks like you saw the correct reply to this post?

    Because now the reply has been overwritten with my post on another thread.
    Can you confirm that you saw the correct reply at one point ?

    Thanks,
    -- MikeR

    MikerRoo Guest

  6. #5

    Default Re: retrieve sql from database

    I saw the reply--fortunately the entire text is emailed when you make your post.

    I'm reproducing it here in case anyone else is following the thread:

    You can try playing with the Evaluate() function but I believe you will find
    that it's not possible to execute a tag like <cfqueryparam> this way.

    If reverting to plain SQL, remember the PreserveSingleQuotes() function.

    To store SQL and still be able to use parameterized queries, you'll might
    pre-parse the SQL like so:

    Create 2 tables:
    1) Main SQL has at least these columns:
    1.a) ID
    1.b) Pre where-clause SQL text.
    1.c) Post where-clause SQL text.

    2) Parameterized Where-Clause table has at least these columns:
    2.a) ID
    2.b) FKey into table 1
    2.c) SQL column name and operator, (EG. "name = ")
    2.d) cfsqltype value
    2.e) CF variable name
    2.xxx ) Additional columns for additional attributes like maxlength.

    Using these two tables you can build a parameterized SQL call.
    Of course, fancy sub-selects, etc. could get messy.

    -- MikeR



    healey_mark Guest

  7. #6

    Default Re: retrieve sql from database

    Thank you.
    MikerRoo 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