title: How to insert another UPDATE SQL command to execute in this code, which use another SQL command to delete one or multiple records
body: <p>I have this code work for deleting one or multiple records from order table when user select order from checkboxes. Now that I have inventory module, I want my inventory record update qty (add the product quantity back to current inventory) once the order had been canceled. </p>
  
  <p>Actually, this shouldn't be problem if the code was implement for delete one record at a time. However, this deleting code is made for deleting multiple records which, with  my skill, I couldn't figure out how to add another updating Sql command into. So could you please help me. Thank you very much.</p>
  
  <p>Below is my existing code..</p>
  
  <pre><code>&lt;%
      call navigation
      url = main_area &amp; "?" &amp; "page=" &amp; page_current 
      return_page = "../backend/" &amp;  url
      req_status = request("type")
      if req_status = "restore" then
          req_status = False
      else
          req_status = True
      end if
  
      record = request("bill_id")
      timestamp = now()
      record = trim(record)
      if len(record) &gt; 3 then   ' multiple records was selected
          arrVals = split(record,",")             
  
  
          strSql = ""
          strSql = strSql &amp; "DELETE * FROM tbl_bill_total WHERE "     
          for i = 0 to ubound(arrVals)
               if i = 0 then           
                strSql = strSql &amp; "bill_id IN ("&amp; trim(arrVals(i)) &amp; "    "
               else
                strSql = strSql &amp; ","&amp; trim(arrVals(i)) &amp; ""
               end if
          next
          strSql = strSql &amp; ") "
  
          strSql2 = strSql2 &amp; "DELETE * FROM tbl_order WHERE "    
          for t = 0 to ubound(arrVals)
               if t = 0 then
                strSql2 = strSql2 &amp; " tbl_order.bill_id IN ("&amp; trim(arrVals(t)) &amp; "    "
               else
                strSql2 = strSql2 &amp; ","&amp; trim(arrVals(t)) &amp; ""
               end if
          next
          strSql2 = strSql2 &amp; "); "       
  
      else
  
          strSql  = "DELETE * FROM tbl_bill_total WHERE bill_id=" &amp; record &amp; " "  
          strSql2  = "DELETE * FROM tbl_order WHERE bill_id =" &amp; record &amp; " " 
      end if
  
  
  
  
  Call DBConnOpen()
  Set Rs = Server.CreateObject("ADODB.Recordset")
  response.write strSql
  
  conn.Execute strSql
  conn.Execute strSql2
  Call DBConnClose()
  
  response.redirect return_page
  %&gt;
  </code></pre>
  
  <p>and this is the SQL statement that I want to add into. Since it need pd_id to execute, I think this should be execute before execute the above SQL statements. </p>
  
  <pre><code>Set rsOrder = conn.Execute("SELECT * FROM tbl_order WHERE bill_id = " &amp; record &amp; "" )           
  pd_id = rsOrder.fields.item("pd_id")
  od_qty = rsOrder.fields.item("od_qty")
  
  
  Set rsInventory = conn.Execute("UPDATE tbl_inventory SET inv_qty_act = inv_qty_act + " &amp; od_qty &amp; ", inv_date =  " &amp; date() &amp; " WHERE pd_id = '" &amp; pd_id &amp; "'"  )   
  </code></pre>
  
  <p><br><br>
  <b>(Working Code)</b> <br>
  With @John provided solution now it can update qty back to database for one/multiple records selected.</p>
  
  <p>Below is the working code that had eliminated addition ')' </p>
  
  <pre><code>&lt;%
  Call DBConnOpen()
  Set Rs = Server.CreateObject("ADODB.Recordset")
  
      call navigation
      url = main_area &amp; "?" &amp; "page=" &amp; page_current 
      return_page = "../backend/" &amp;  url
      req_status = request("type")
      if req_status = "restore" then
          req_status = False
      else
          req_status = True
      end if
  
      record = request("bill_id")
      timestamp = now()
      record = trim(record)
      if len(record) &gt; 3 then   ' multiple records was selected
          arrVals = split(record,",")             
  
  
          strSql = ""
          strSql = strSql &amp; "DELETE * FROM tbl_bill_total WHERE "     
          for i = 0 to ubound(arrVals)
               if i = 0 then           
                strSql = strSql &amp; "bill_id IN ("&amp; trim(arrVals(i)) &amp; "    "
               else
                strSql = strSql &amp; ","&amp; trim(arrVals(i)) &amp; ""
               end if
          next
          strSql = strSql &amp; ") "
  
          strSql2 = strSql2 &amp; "DELETE * FROM tbl_order WHERE "    
          for t = 0 to ubound(arrVals)
  
          Set rsOrder = conn.Execute("SELECT * FROM tbl_order WHERE bill_id = " &amp; arrVals(t) &amp; "")     
              pd_id = rsOrder.fields.item("pd_id")  
              od_qty = rsOrder.fields.item("od_qty")  
                  od_qty  = DzToPcs(od_qty)
          conn.Execute("UPDATE tbl_inventory SET inv_qty_act = inv_qty_act + " &amp; od_qty &amp; ", inv_date =  " &amp; date() &amp; " WHERE pd_id = '" &amp; pd_id &amp; "'"  ) 
  
               if t = 0 then
                strSql2 = strSql2 &amp; " tbl_order.bill_id IN ("&amp; trim(arrVals(t)) &amp; "    "
  
               else
                strSql2 = strSql2 &amp; ","&amp; trim(arrVals(t)) &amp; ""
               end if
          next
          strSql2 = strSql2 &amp; "); "       
  
  
  '   response.Write "strSql3 = " &amp; strSql3
      else
  
  
          Set rsOrder = conn.Execute("SELECT * FROM tbl_order WHERE bill_id = " &amp; record &amp; " ")             
              pd_id = rsOrder.fields.item("pd_id")  
              od_qty = rsOrder.fields.item("od_qty")  
                  od_qty  = DzToPcs(od_qty)   
          conn.Execute("UPDATE tbl_inventory SET inv_qty_act = inv_qty_act + " &amp; od_qty &amp; ", inv_date =  date() WHERE pd_id = '" &amp; pd_id &amp; "'"  ) 
  
          strSql  = "DELETE * FROM tbl_bill_total WHERE bill_id=" &amp; record &amp; " "  
          strSql2  = "DELETE * FROM tbl_order WHERE bill_id =" &amp; record &amp; " " 
      end if
  
  
  
  
  'Call DBConnOpen() --&gt; move to top line
  'Set Rs = Server.CreateObject("ADODB.Recordset") --&gt; move to top line
  'response.write strSql2
  
  conn.Execute strSql
  conn.Execute strSql2
  Call DBConnClose()
  
  response.redirect return_page
  %&gt;
  </code></pre>