I think I just need another set of eyes taking a look at this. I'm executing the below SQL in a module. I keep getting a "Syntax error in JOIN operation." error with "QRY_SEL_D100_DATA_TM_D.GROUP" highlighted at the beginning of the SELECT statement. Any suggestions would be much appreciated.
Code:
lngCatID = 9
dtMonthBeg = funDataDate()
strMonth = UCase(Format(dtMonthBeg, "mmm"))
lngMonthIndex = DLookup("LOOKUP_ID", "TBL_LOOKUP_VALUES", "[LOOKUP_DESC] = '" & strMonth & "'")
strLevel = "D"
mySQL = "INSERT INTO TBL_RESULTS ( [GROUP], REGION, DISTRICT, CATEGORY, LEVEL_FLAG, RESULTS_MONTH, RESULTS_MONTH_BEG, " & _
"MONTH_RESULTS, YTD_RESULTS ) " & _
"SELECT QRY_SEL_D100_DATA_TM_" & strLevel & ".GROUP, QRY_SEL_D100_DATA_TM_" & strLevel & ".REGION, " & _
"QRY_SEL_D100_DATA_TM_" & strLevel & ".DISTRICT, " & lngCatID & ", '" & strLevel & "', " & lngMonthIndex & ", #" & dtMonthBeg & "#, " & _
"IIf(Month([QRY_SEL_D100_DATA_TM_" & strLevel & "]![Month_Begin])=9," & _
"([QRY_SEL_D100_DATA_TM_" & strLevel & "]![D100_YTD_TY])/([QRY_SEL_D100_DATA_TM_" & strLevel & "]![STORE_SALES_YTD_TY])," & _
"([QRY_SEL_D100_DATA_TM_" & strLevel & "]![D100_YTD_TY]-[QRY_SEL_D100_DATA_LM_" & strLevel & "]![D100_YTD_TY])/" & _
"([QRY_SEL_D100_DATA_TM_" & strLevel & "]![STORE_SALES_YTD_TY]-[QRY_SEL_D100_DATA_LM_" & strLevel & "]![STORE_SALES_YTD_TY])), " & _
"[QRY_SEL_D100_DATA_TM_" & strLevel & "]![D100_YTD_TY]/[QRY_SEL_D100_DATA_TM_" & strLevel & "]![STORE_SALES_YTD_TY] " & _
"FROM QRY_SEL_D100_DATA_TM_" & strLevel & ", QRY_SEL_D100_DATA_LM_" & strLevel & " INNER JOIN QRY_SEL_D100_DATA_LM_" & strLevel & " " & _
"ON QRY_SEL_D100_DATA_TM_" & strLevel & ".DISTRICT = QRY_SEL_D100_DATA_LM_" & strLevel & ".DISTRICT;"
CurrentDb.Execute mySQL, dbFailOnError