I am trying to put the following sql into VBA to run 134 different districts.
SELECT cash.REGION, cash.DISTRICT, cash.STORE, cash.LINE, cash.IPLCD, cash.IPCODE, cash.cash_sls_total, 1-(cash.cash_cost_total/cash.cash_sls_total), installer.charge_sls_total, 1-(installer.chg_cost_total/installer.charge_sls_total), (cash.cash_sls_total+installer.charge_sls_total), 1-((cash.cash_cost_total+installer.chg_cost_total)/(cash.cash_sls_total+installer.charge_sls_total)), `ytd and prev ytd sls`.YTD_TOTAL_SALES_AT_RETAIL, `ytd and prev ytd sls`.PRV_YTD_TOTAL_SALES_AT_RETAIL, internal_one.sum_of_internal, month_end_inv_one.inv_val
FROM cash cash, installer installer, internal_one internal_one, month_end_inv_one month_end_inv_one, `ytd and prev ytd sls` `ytd and prev ytd sls`
WHERE month_end_inv_one.DISTRICT = `ytd and prev ytd sls`.DISTRICT AND month_end_inv_one.IPCODE = `ytd and prev ytd sls`.SUB_CODE AND month_end_inv_one.IPLCD = `ytd and prev ytd sls`.PRODUCT_LINE_CODE AND month_end_inv_one.LINE = `ytd and prev ytd sls`.LINE AND month_end_inv_one.REGION = `ytd and prev ytd sls`.REGION AND month_end_inv_one.STORE_NUMBER = `ytd and prev ytd sls`.STORE AND cash.DISTRICT = installer.DISTRICT AND cash.IPCODE = installer.IPCODE AND cash.IPLCD = installer.IPLCD AND cash.LINE = installer.LINE AND cash.REGION = installer.REGION AND cash.STORE = installer.STORE AND installer.DISTRICT = internal_one.DISTRICT AND installer.IPCODE = internal_one.IPCODE AND installer.IPLCD = internal_one.IPLCD AND installer.LINE = internal_one.LINE AND installer.REGION = internal_one.REGION AND installer.STORE = internal_one.STORE AND internal_one.DISTRICT = month_end_inv_one.DISTRICT AND internal_one.IPCODE = month_end_inv_one.IPCODE AND internal_one.IPLCD = month_end_inv_one.IPLCD AND internal_one.LINE = month_end_inv_one.LINE AND internal_one.REGION = month_end_inv_one.REGION AND internal_one.STORE = month_end_inv_one.STORE_NUMBER AND ((cash.DISTRICT In (21)))
The trouble I am running into is a compile error stating that a list seperator or ) is expected. I have looked at every period, comma, quotation mark and list seperator. I can not find what is wrong. I thought that maybe I was putting too much criteria in the sql. I then tried to remove some of the joins and ended up with duplicate information. Then I tried to put unique values and group records in Excel to get rid of duplicate information, and it did not work.
Is there anything I can do? If it is too many joins and criteria, is there a way around it? I would really appreciate any suggestions.
I had also planned on re-writing this report, but I was asked to produce the 134 district reports by Monday, so I need a fix until I can get the report right.
Thanks in advance!
SELECT cash.REGION, cash.DISTRICT, cash.STORE, cash.LINE, cash.IPLCD, cash.IPCODE, cash.cash_sls_total, 1-(cash.cash_cost_total/cash.cash_sls_total), installer.charge_sls_total, 1-(installer.chg_cost_total/installer.charge_sls_total), (cash.cash_sls_total+installer.charge_sls_total), 1-((cash.cash_cost_total+installer.chg_cost_total)/(cash.cash_sls_total+installer.charge_sls_total)), `ytd and prev ytd sls`.YTD_TOTAL_SALES_AT_RETAIL, `ytd and prev ytd sls`.PRV_YTD_TOTAL_SALES_AT_RETAIL, internal_one.sum_of_internal, month_end_inv_one.inv_val
FROM cash cash, installer installer, internal_one internal_one, month_end_inv_one month_end_inv_one, `ytd and prev ytd sls` `ytd and prev ytd sls`
WHERE month_end_inv_one.DISTRICT = `ytd and prev ytd sls`.DISTRICT AND month_end_inv_one.IPCODE = `ytd and prev ytd sls`.SUB_CODE AND month_end_inv_one.IPLCD = `ytd and prev ytd sls`.PRODUCT_LINE_CODE AND month_end_inv_one.LINE = `ytd and prev ytd sls`.LINE AND month_end_inv_one.REGION = `ytd and prev ytd sls`.REGION AND month_end_inv_one.STORE_NUMBER = `ytd and prev ytd sls`.STORE AND cash.DISTRICT = installer.DISTRICT AND cash.IPCODE = installer.IPCODE AND cash.IPLCD = installer.IPLCD AND cash.LINE = installer.LINE AND cash.REGION = installer.REGION AND cash.STORE = installer.STORE AND installer.DISTRICT = internal_one.DISTRICT AND installer.IPCODE = internal_one.IPCODE AND installer.IPLCD = internal_one.IPLCD AND installer.LINE = internal_one.LINE AND installer.REGION = internal_one.REGION AND installer.STORE = internal_one.STORE AND internal_one.DISTRICT = month_end_inv_one.DISTRICT AND internal_one.IPCODE = month_end_inv_one.IPCODE AND internal_one.IPLCD = month_end_inv_one.IPLCD AND internal_one.LINE = month_end_inv_one.LINE AND internal_one.REGION = month_end_inv_one.REGION AND internal_one.STORE = month_end_inv_one.STORE_NUMBER AND ((cash.DISTRICT In (21)))
The trouble I am running into is a compile error stating that a list seperator or ) is expected. I have looked at every period, comma, quotation mark and list seperator. I can not find what is wrong. I thought that maybe I was putting too much criteria in the sql. I then tried to remove some of the joins and ended up with duplicate information. Then I tried to put unique values and group records in Excel to get rid of duplicate information, and it did not work.
Is there anything I can do? If it is too many joins and criteria, is there a way around it? I would really appreciate any suggestions.
I had also planned on re-writing this report, but I was asked to produce the 134 district reports by Monday, so I need a fix until I can get the report right.
Thanks in advance!