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

  1. #1

    Default Complicated Insert

    I have several rows of data in a table which i want to insert into only 1 row
    in another table.
    Is it possible to do an insert query from a select query?
    Alternatively how can i create a list variable from a query?
    eg query:
    SELECT Name FROM Names WHERE Country = '#Form.Country#'

    So the list will look like: name1, name2, etc...

    xSeanx Guest

  2. Similar Questions and Discussions

    1. Complicated text flow
      Please see the this example at <http://iwillglo.com/practice/overset.html> I have a journal that is set up as shown in the example with article...
    2. Complicated variable
      I have a database query, which i output and also use 2 loops in. optionx and qtyx are loop index's. i want to use those loop index's to output a...
    3. pattern need help... so complicated
      hi, need some help over how to create this pattern... <http://img47.photobucket.com/albums/v144/kylekwan/pattern.jpg> I'm using AI 10. Have...
    4. A bit more complicated....
      can any one help me with this ? if i press the button refresh in my browser my movie stop playing i tried to insert a rewind in my script but it...
    5. Requesting help with complicated query
      Hi, Sorry, for the lack of info in the title. Just don't know how to simplify it. I have previously been asked to post my questions in a certain...
  3. #2

    Default Re: Complicated Insert

    To do this totally in a single query would depend on what db your using.

    But, you could do
    <cfquery name="Q1">
    SELECT Name FROM Names WHERE Country = '#Form.Country#'
    </cfquery>
    <cfquery name="Q2">
    Insert Into myTable(
    <cfloop from="1" to="#Q1.RecordCount#" index="idx">Name#idx#</cfloop>
    Values(
    <cfloop from="1" to="#Q1.RecordCount#" index="idx">
    '#Q1.Name[idx]#'
    <cfif idx NEQ Q1.RecordCount>
    ,
    </cfif>
    </cfloop>

    Ken


    The ScareCrow Guest

  4. #3

    Default Re: Complicated Insert

    I hope you're not planning on storing lists like that in the database. It is not good, usually.
    OldCFer Guest

  5. #4

    Default Re: Complicated Insert

    Hi,

    You can write queries like:

    insert into tablename
    (
    ..
    )
    select
    ....
    from
    someothertablename

    just make sure the same number of colums and data types match.

    You can use
    QuotedValueList(queryname.fieldname) to create a quoted comma delimited list

    Scott*e 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