2 Replies Latest reply on Jul 24, 2006 8:28 PM by Dan Bracuk

    cfloop

    JohnGree Level 1
      Hi i have a query and a insert query, what i need to do is insert into my SMS_Records table from the main query, but i need to loop through each record from the main query

      just not sure how to do this?

      can someone help
        • 1. Re: cfloop
          Level 7
          <cfloop query="Send">
          > <cfquery datasource="iluvcricket">
          > INSERT INTO SMS_Records
          > SET
          > DateOfSMS = #todayDate#,
          > SentTo = #Send.PlayerPhone#,
          > ClubID = '#session.ClubLogin#',
          > Cost = 0.15
          > </CFQUERY>
          </cfloop>

          JohnGree wrote:
          > Hi i have a query and a insert query, what i need to do is insert into my
          > SMS_Records table from the main query, but i need to loop through each record
          > from the main query
          >
          > just not sure how to do this?
          >
          > can someone help
          >
          > <CFQUERY datasource="iluvcricket" Name="Send">
          > SELECT hh.PlayerPhone, KK.SMS_Password, KK.Club_Abbrev, KK.ContactEmail
          > FROM SMS_Players_Table hh, SMS_Clubs_Table KK
          > WHERE kk.ClubID = '#session.ClubLogin#' AND hh.ToSMS = '1'
          > </cfquery>
          >
          > <cfset todayDate = Now()>
          >
          > <cfquery datasource="iluvcricket">
          > INSERT INTO SMS_Records
          > SET
          > DateOfSMS = #todayDate#,
          > SentTo = #Send.PlayerPhone#,
          > ClubID = '#session.ClubLogin#',
          > Cost = 0.15
          > </CFQUERY>
          >
          • 2. Re: cfloop
            Dan Bracuk Level 5
            First of all, the keyword set is used for update queries, not inserts. Second, you only need one query and you don't need a loop. It would start like

            insert into sms_records
            (field1, field2, etc)
            select