Skip to main content
Inspiring
June 28, 2007
Question

CFLoop question

  • June 28, 2007
  • 1 reply
  • 543 views
In CF, I have a simple query that just gets data based on a select. I then want to take each of the records found and insert them into another table for other processing later on. Just doing a simple insert only adds the first record, so I am using a cfloop query="name of the first query" to try and insert all of the records. Is this the correct way to do this, or is there another way.
When I run it this way, it seems the new table gets populated with duplicate records, and now it seems to be caught in an infinite loop, it is still not done.

thanks for any help and suggestions.
    This topic has been closed for replies.

    1 reply

    Inspiring
    June 28, 2007
    It doesn't sound like you need loop. Sounds like you can combine the select and insert into one query.

    INSERT INTO OtherTable (Col1, Col2)
    SELECT Col1, Col2
    FROM SomeTable
    WHERE .. some conditions...
    trojnfnAuthor
    Inspiring
    June 28, 2007
    I would insert first ?

    Or would I select, from, where, and then insert ?
    Inspiring
    June 28, 2007
    That query inserts the selected records. It's a combo, basically it will run a select query and insert those results into the new table.