Colin@Toyota
What's an Access?
- Local time
- Today, 16:08
- Joined
- May 2, 2006
- Messages
- 203
Hi guys! Happy new year to everyone!
I have a couple of existing queries that come together to produce sales information. Right now, it is done only at the national level but we are looking to calculate it by zone (atlantic, prairie, quebec, etc.).
I have another table that is not currently part of this query that contains the information about which zone each dealer belongs to. I just dont know how to go about adding it into this query...
In the SQL, I have included comments as to my understanding of what is going on. If anyone notices any mistakes, please correct me! I appreciate your help!
I have a couple of existing queries that come together to produce sales information. Right now, it is done only at the national level but we are looking to calculate it by zone (atlantic, prairie, quebec, etc.).
I have another table that is not currently part of this query that contains the information about which zone each dealer belongs to. I just dont know how to go about adding it into this query...
In the SQL, I have included comments as to my understanding of what is going on. If anyone notices any mistakes, please correct me! I appreciate your help!
Code:
' select all into this table
SELECT * INTO [19c) vehicle_sales_temp]
' these fields
FROM
' retail sales only, count each record as a sale
[SELECT 'RETAIL' AS TYPE, Count(*) AS SALES,
' extract year and month, put a space between and set as the transaction date
Left([DWP_F_DEALER_VEHICLE_INVENTORY]![PROCESS_DATE_SID],4) & ' ' & Mid([DWP_F_DEALER_VEHICLE_INVENTORY]![PROCESS_DATE_SID],5,2) AS TRANSACTION_DATE
' these tables
FROM DWP_F_DEALER_VEHICLE_INVENTORY INNER JOIN DWP_D_VEHICLE_TYPE_APX
' the inner join occurs on this field
ON DWP_F_DEALER_VEHICLE_INVENTORY.VEHICLE_TYPE_SID = DWP_D_VEHICLE_TYPE_APX.VEHICLE_TYPE_SID
' select records where the process date is between the following dates
WHERE (((DWP_F_DEALER_VEHICLE_INVENTORY.PROCESS_DATE_SID) Between 20080101 And 20081231)
' and where series in the first table are found in the next table
AND ((DWP_D_VEHICLE_TYPE_APX.SERIES_CD) IN (SELECT [19c1) vehicle_abbreviation_temp].VehicleAbbreviation FROM [19c1) vehicle_abbreviation_temp]) ))
' group by RETAIL first, then by date
GROUP BY 'RETAIL', Left([DWP_F_DEALER_VEHICLE_INVENTORY]![PROCESS_DATE_SID],4) & ' ' & Mid([DWP_F_DEALER_VEHICLE_INVENTORY]![PROCESS_DATE_SID],5,2)
' also select all records into the same table
UNION ALL
' wholesale only, count each record as a sale
SELECT 'W/S' AS TYPE, Count(*) AS SALES,
' extract year and month, put a space between and set as the transaction date
Left([DWP_F_DEALER_VEHICLE_INVENTORY]![WHOLESALE_DATE_SID],4) & ' ' & Mid([DWP_F_DEALER_VEHICLE_INVENTORY]![WHOLESALE_DATE_SID],5,2) AS TRANSACTION_DATE
' these tables
FROM DWP_F_DEALER_VEHICLE_INVENTORY INNER JOIN DWP_D_VEHICLE_TYPE_APX
' the inner join occurs on this field
ON DWP_F_DEALER_VEHICLE_INVENTORY.VEHICLE_TYPE_SID = DWP_D_VEHICLE_TYPE_APX.VEHICLE_TYPE_SID
' select records where the wholesale date is between the following dates
WHERE (((DWP_F_DEALER_VEHICLE_INVENTORY.WHOLESALE_DATE_SID) Between 20080101 And 20081231)
' and where the series in the first table are found in the second table
AND ((DWP_D_VEHICLE_TYPE_APX.SERIES_CD) IN (SELECT [19c1) vehicle_abbreviation_temp].VehicleAbbreviation FROM [19c1) vehicle_abbreviation_temp]) ))
' group by W/S first, then by date
GROUP BY 'W/S', Left([DWP_F_DEALER_VEHICLE_INVENTORY]![WHOLESALE_DATE_SID],4) & ' ' & Mid([DWP_F_DEALER_VEHICLE_INVENTORY]![WHOLESALE_DATE_SID],5,2) ].
' temp table
AS vehicleSales;