Littlemalky
Board Regular
- Joined
- Jan 14, 2011
- Messages
- 223
Hi, I'm curious if there is a more efficient way to execute multiple SQL strings? I'm basically running a series of append queries and will be layering in a few more. Currently, this is my structure, but I'm sure there is a faster way to run this? Also, does each SQL string have to have a different name because it's kind of annoying to Dim every single one? Any advise?
Code:
Private Sub COMMISSION_PAYOUT_APPEND()
Dim strSQL_REP_CFS_ESR_L1, strSQL_REP_CFS_ESR_L2, strSQL_REP_CFS_ESR_L3 As String
'Append REPS & CFS L1_PAYOUT to tbl_COMMISSIONS_PAYOUTS
strSQL_REP_CFS_ESR_L1 = "INSERT INTO tbl_COMMISSIONS_PAYOUTS_1 ( PAYOUT_DATE, REGION_ID, EMPLOYEE_ID, SALES_ROLE_ID, POSITION_ID, PRODUCT_ID, PAYOUT_CATEGORY, " & _
"NUMBER_OF_TERRITORIES, PAYOUT_AMT ) SELECT DateSerial(Year(Date()),Month(Date()),0) AS PAYOUT_DATE, " & _
"qry_COMMISSION_PAYOUT_REP_CFS_ESR_QTD.REGION_ID, qry_COMMISSION_PAYOUT_REP_CFS_ESR_QTD.EMPLOYEE_ID, " & _
"qry_COMMISSION_PAYOUT_REP_CFS_ESR_QTD.SALES_ROLE_ID, qry_COMMISSION_PAYOUT_REP_CFS_ESR_QTD.[POSITION ID], " & _
"qry_COMMISSION_PAYOUT_REP_CFS_ESR_QTD.PRODUCT_ID, 'L1' AS PAYOUT_CATEGORY, qry_COMMISSION_PAYOUT_REP_CFS_ESR_QTD.NUM_OF_TERRITORIES, " & _
"qry_COMMISSION_PAYOUT_REP_CFS_ESR_QTD.[L1_PAYOUT] AS PAYOUT_AMT FROM qry_COMMISSION_PAYOUT_REP_CFS_ESR_QTD " & _
"INNER JOIN qry_ACTIVE_EMPLOYEES ON (qry_COMMISSION_PAYOUT_REP_CFS_ESR_QTD.EMPLOYEE_ID = qry_ACTIVE_EMPLOYEES.EMPLOYEE_ID) " & _
"AND (qry_COMMISSION_PAYOUT_REP_CFS_ESR_QTD.[POSITION ID] = qry_ACTIVE_EMPLOYEES.POSITION_ID)"
CurrentDb.Execute strSQL_REP_CFS_ESR_L1, dbSeeChanges
CurrentDb.Close
'Append REPS & CFS L2_PAYOUT to tbl_COMMISSIONS_PAYOUTS
strSQL_REP_CFS_ESR_L2 = "INSERT INTO tbl_COMMISSIONS_PAYOUTS_1 ( PAYOUT_DATE, REGION_ID, EMPLOYEE_ID, SALES_ROLE_ID, POSITION_ID, PRODUCT_ID, PAYOUT_CATEGORY, " & _
"NUMBER_OF_TERRITORIES, PAYOUT_AMT ) SELECT DateSerial(Year(Date()),Month(Date()),0) AS PAYOUT_DATE, " & _
"qry_COMMISSION_PAYOUT_REP_CFS_ESR_QTD.REGION_ID, qry_COMMISSION_PAYOUT_REP_CFS_ESR_QTD.EMPLOYEE_ID, " & _
"qry_COMMISSION_PAYOUT_REP_CFS_ESR_QTD.SALES_ROLE_ID, qry_COMMISSION_PAYOUT_REP_CFS_ESR_QTD.[POSITION ID], " & _
"qry_COMMISSION_PAYOUT_REP_CFS_ESR_QTD.PRODUCT_ID, 'L2' AS PAYOUT_CATEGORY, qry_COMMISSION_PAYOUT_REP_CFS_ESR_QTD.NUM_OF_TERRITORIES, " & _
"qry_COMMISSION_PAYOUT_REP_CFS_ESR_QTD.[L2_PAYOUT] AS PAYOUT_AMT FROM qry_COMMISSION_PAYOUT_REP_CFS_ESR_QTD " & _
"INNER JOIN qry_ACTIVE_EMPLOYEES ON (qry_COMMISSION_PAYOUT_REP_CFS_ESR_QTD.EMPLOYEE_ID = qry_ACTIVE_EMPLOYEES.EMPLOYEE_ID) " & _
"AND (qry_COMMISSION_PAYOUT_REP_CFS_ESR_QTD.[POSITION ID] = qry_ACTIVE_EMPLOYEES.POSITION_ID)"
CurrentDb.Execute strSQL_REP_CFS_ESR_L2, dbSeeChanges
CurrentDb.Close
'Append REPS & CFS L3_PAYOUT to tbl_COMMISSIONS_PAYOUTS
strSQL_REP_CFS_ESR_L3 = "INSERT INTO tbl_COMMISSIONS_PAYOUTS_1 ( PAYOUT_DATE, REGION_ID, EMPLOYEE_ID, SALES_ROLE_ID, POSITION_ID, PRODUCT_ID, PAYOUT_CATEGORY, " & _
"NUMBER_OF_TERRITORIES, PAYOUT_AMT ) SELECT DateSerial(Year(Date()),Month(Date()),0) AS PAYOUT_DATE, " & _
"qry_COMMISSION_PAYOUT_REP_CFS_ESR_QTD.REGION_ID, qry_COMMISSION_PAYOUT_REP_CFS_ESR_QTD.EMPLOYEE_ID, " & _
"qry_COMMISSION_PAYOUT_REP_CFS_ESR_QTD.SALES_ROLE_ID, qry_COMMISSION_PAYOUT_REP_CFS_ESR_QTD.[POSITION ID], " & _
"qry_COMMISSION_PAYOUT_REP_CFS_ESR_QTD.PRODUCT_ID, 'L3' AS PAYOUT_CATEGORY, qry_COMMISSION_PAYOUT_REP_CFS_ESR_QTD.NUM_OF_TERRITORIES, " & _
"qry_COMMISSION_PAYOUT_REP_CFS_ESR_QTD.[L3_PAYOUT] AS PAYOUT_AMT FROM qry_COMMISSION_PAYOUT_REP_CFS_ESR_QTD " & _
"INNER JOIN qry_ACTIVE_EMPLOYEES ON (qry_COMMISSION_PAYOUT_REP_CFS_ESR_QTD.EMPLOYEE_ID = qry_ACTIVE_EMPLOYEES.EMPLOYEE_ID) " & _
"AND (qry_COMMISSION_PAYOUT_REP_CFS_ESR_QTD.[POSITION ID] = qry_ACTIVE_EMPLOYEES.POSITION_ID)"
CurrentDb.Execute strSQL_REP_CFS_ESR_L3, dbSeeChanges
CurrentDb.Close
End Sub