Query datas to add to another table :))

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • freddie007
    New Member
    • Sep 2008
    • 20

    Query datas to add to another table :))

    After I query an sales table, i would like to add the outstanding unpaid to another table


    Output example
    id_order company amount

    3 A 30
    4 B 40
    6 C 45



    How do I add the above to another table example tbl_outstanding
    (use array??? them cfinsert into the database??))
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    I wouldn't advise cfinsert use. Use cfquery instead.

    Does the format of the table to be added to match the query returned?

    Comment

    • freddie007
      New Member
      • Sep 2008
      • 20

      #3
      SorryI do not understand .....

      I need to add the data that I have cfquery ..ed

      and add this database into another table

      I thought firstly I would need some array scripts
      and that row by row insert into the second table

      Sorry I am not clear in my explanation

      Comment

      • freddie007
        New Member
        • Sep 2008
        • 20

        #4
        Sorry I do not understand .....

        I need to add the data that I have cfquery ..ed from table 1

        and add this data (ouput) into another table 2

        I thought firstly I would need some array scripts
        and that row by row insert into the second table 2

        Sorry I am not clear in my explanation

        Comment

        • acoder
          Recognized Expert MVP
          • Nov 2006
          • 16032

          #5
          You don't need an array. You can just loop over the query, take the values and insert them into the other table.

          Comment

          • freddie007
            New Member
            • Sep 2008
            • 20

            #6
            Ok, goodidea. thanks.

            U have been great!

            1 more thing, comparing cfinsert statement using cfset form

            to using cfquery insert,

            will cfquery insert be faster if there are many record to add at the same time

            Comment

            • acoder
              Recognized Expert MVP
              • Nov 2006
              • 16032

              #7
              I'm not sure about speed, but cfinsert is limited and susceptible to SQL injection attacks. cfquery is more powerful and flexible and if used in conjunction with cfqueryparam is safer.

              Comment

              • jKara
                New Member
                • Nov 2008
                • 5

                #8
                Originally posted by freddie007
                After I query an sales table, i would like to add the outstanding unpaid to another table
                Instead of using a query, you could also use a select. It can insert multiple records from one table to another in a single statement.

                INSERT INTO OtherTable (Column)
                SELECT SomeColumn
                FROM FirstTable
                WHERE ....

                Comment

                • acoder
                  Recognized Expert MVP
                  • Nov 2006
                  • 16032

                  #9
                  jKara, welcome to Bytes.

                  You make a good point. Thanks for your contribution.

                  Comment

                  • jKara
                    New Member
                    • Nov 2008
                    • 5

                    #10
                    Originally posted by acoder
                    jKara, welcome to Bytes.

                    You make a good point. Thanks for your contribution.
                    Thanks!

                    (...this extra text is because messages must be at 20 characters)

                    Comment

                    Working...