4 Replies Latest reply on Jul 23, 2008 11:34 AM by Dan Bracuk

    Insert Query

    Level 7
      Hello - What is the best method to take the results of a query that
      returns a series of records based on an order number (ex. Order Number
      is 1234ABC and returns 5 records that include sku, qty and price) and
      insert the query results into a db table?

      Any help is appreciated.

      Thanks,
      Steve
        • 1. Re: Insert Query
          Dan Bracuk Level 5
          If the data is already coming from a db query, the best method might be to do nothing.
          • 2. Re: Insert Query
            Level 7
            Steve Miller wrote:
            > Hello - What is the best method to take the results of a query that
            > returns a series of records based on an order number (ex. Order Number
            > is 1234ABC and returns 5 records that include sku, qty and price) and
            > insert the query results into a db table?
            >
            > Any help is appreciated.
            >
            > Thanks,
            > Steve

            This is a bit of a strange question as worded. You are querying a
            database getting data from one or more tables. And you now want to
            store this data into a database table?

            Anyway, the basic idea of putting repeating data into a table is simple.
            Loop over data. Build <cfquery...> insert SQL block for each iteration.
            Rinse. Repeat.

            • 3. Re: Insert Query
              Level 7
              This is actually a case where a customer has placed a previous order
              (which is where the order number comes from) and would like to duplicate
              the order. The previous order is displayed on the page with the option
              to duplicate (submit reorder). Make more sense?

              Dan Bracuk wrote:
              > If the data is already coming from a db query, the best method might be to do nothing.
              • 4. Re: Insert Query
                Dan Bracuk Level 5
                quote:

                Originally posted by: Newsgroup User
                This is actually a case where a customer has placed a previous order
                (which is where the order number comes from) and would like to duplicate
                the order. The previous order is displayed on the page with the option
                to duplicate (submit reorder). Make more sense?

                Dan Bracuk wrote:
                > If the data is already coming from a db query, the best method might be to do nothing.


                That would make it a new order then, would it not?

                The sql would be something like
                insert into mytable
                (order_number, field2, etc)
                select 'new_order_number', field2, etc
                from mytable
                where order_number = 'old_order_number'