Re: MERGING TWO QUERIES
From: Douglas J. Steele (NOSPAM_djsteele_at_NOSPAM_canada.com)
Date: 09/03/04
- Next message: Andrew: "Re: In TblA, but not in TblB, C, D, or E..."
- Previous message: Frank Stone: "criteria"
- In reply to: Kelli McCann: "MERGING TWO QUERIES"
- Next in thread: Kelli McCann: "Re: MERGING TWO QUERIES"
- Reply: Kelli McCann: "Re: MERGING TWO QUERIES"
- Reply: Kelli McCann: "Re: MERGING TWO QUERIES"
- Messages sorted by: [ date ] [ thread ]
Date: Fri, 3 Sep 2004 12:16:42 -0400
SELECT [Maintenance Purchases].TruckID AS TruckID, Sum([Maintenance
Purchases].Amount) AS Amount, Sum(Mileage.Miles) AS Miles,
Format([InvoiceDate],"mmm") AS [Month],
DatePart("yyyy",[InvoiceDate]) AS [Year]
FROM [Maintenance Purchases]
WHERE (((DatePart("yyyy",[InvoiceDate])) Between 2003 And 2004))
GROUP BY [Maintenance Purchases].TruckID, Format([InvoiceDate],"mmm"),
DatePart("yyyy",[InvoiceDate]), DatePart("m",[InvoiceDate])
HAVING ((([Maintenance Purchases].TruckID)="00-66"))
ORDER BY [Maintenace Purchases].TruckID, DatePart("yyyy",[InvoiceDate]),
DatePart("m",[InvoiceDate]);
-- Doug Steele, Microsoft Access MVP http://I.Am/DougSteele (no e-mails, please!) "Kelli McCann" <KelliMcCann@discussions.microsoft.com> wrote in message news:1024ADBE-32E6-49DE-8E2A-B04A811B46EE@microsoft.com... > Hello, > > Below I will post my two queries and the SQL view. I am wondering if these > two queries could actually just be one query. The information comes from two > different tables. If this is possible could someone please post the SQL view > of what the query would look like because I am having some difficulties. > > COST PER MONTH - Query: > > SELECT [Maintenance Purchases].TruckID AS TruckID, Sum([Maintenance > Purchases].Amount) AS Amount, Format([InvoiceDate],"mmm") AS [Month], > DatePart("yyyy",[InvoiceDate]) AS [Year] > FROM [Maintenance Purchases] > WHERE (((DatePart("yyyy",[InvoiceDate])) Between 2003 And 2004)) > GROUP BY [Maintenance Purchases].TruckID, Format([InvoiceDate],"mmm"), > DatePart("yyyy",[InvoiceDate]), DatePart("m",[InvoiceDate]) > HAVING ((([Maintenance Purchases].TruckID)="00-66")) > ORDER BY [Maintenace Purchases].TruckID, DatePart("yyyy",[InvoiceDate]), > DatePart("m",[InvoiceDate]); > > > MILES PER MONTH - Query: > > SELECT Mileage.TruckID AS TruckID, Sum(Mileage.Miles) AS Miles, > Format([MilesDate],"mmm") AS [Month], DatePart("yyyy",[MilesDate]) AS [Year] > FROM Mileage > WHERE (((DatePart("yyyy",[MilesDate])) Between 2003 And 2004)) > GROUP BY Mileage.TruckID, Format([MilesDate],"mmm"), > DatePart("yyyy",[MilesDate]), DatePart("m",[MilesDate]) > HAVING (((Mileage.TruckID)="00-66")) > ORDER BY Mileage.TruckID, DatePart("yyyy",[MilesDate]), > DatePart("m",[MilesDate]); > > > Any help would be great. Thanks. Kelli > >
- Next message: Andrew: "Re: In TblA, but not in TblB, C, D, or E..."
- Previous message: Frank Stone: "criteria"
- In reply to: Kelli McCann: "MERGING TWO QUERIES"
- Next in thread: Kelli McCann: "Re: MERGING TWO QUERIES"
- Reply: Kelli McCann: "Re: MERGING TWO QUERIES"
- Reply: Kelli McCann: "Re: MERGING TWO QUERIES"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|