Hi folks, happy Friday 13th.
I'm hoping you can help me build a query that will return data from several identical tables.
I have six tables each containing the following fields:
As you can see, the query is quite simple, however, I have to run this query separately for each different table and then manually copy and paste the results into a spreadsheet!
I now need to build a query that will pull the data from all 6 tables and return the results in one big query. Can you guys help!?
Let me know if you need any further details about the query above.
Any help greatly appreciated. I'm chin deep in this one.
I'm hoping you can help me build a query that will return data from several identical tables.
I have six tables each containing the following fields:
I use the following query to pull data from one of the tables:ID - SalesExec - Venue - CustDOB - AppDate
1 - John Doe - New York - 01/01/1984 - 01/01/2002
This query returns the following results (this is just one sample record):SELECT M.ID, MV.Venue, LTRIM(MS.Forename) + ' ' + LTRIM(MS.Surname) AS Name, AR1.Range AS Age1, AR2.Range AS Age2, M.AppDate
FROM dbo.TableOne_Main M CROSS JOIN
dbo.tblMain_AgeRanges_A AR1 CROSS JOIN
dbo.tblMain_AgeRanges_B AR2 INNER JOIN
dbo.tblMainVenue MV ON M.Venue = MV.ID INNER JOIN
dbo.tblMainSalesExec MS ON M.SalesExec = MS.ID
WHERE (DATEDIFF(yyyy, M.CustDOB, GETDATE()) BETWEEN AR1.Low AND AR1.High) AND (DATEDIFF(yyyy, M.CustDOB, GETDATE()) BETWEEN AR2.Low AND AR2.High)
GROUP BY M.ID, MV.Venue, LTRIM(MS.Forename) + ' ' + LTRIM(MS.Surname), AR1.Range, AR2.Range, M.AppDate
The AR1.Range, AR2.Range parts of the query group the CustDOB field into age ranges. In the sample result above (John Doe, aged 20) has been grouped into the 18/25 range and the 18/60 range.ID - SalesExec - Venue - Age1 - Age2 - AppDate
=======================================
1 - John Doe - New York - 18/25 - 18/60 - 01/01/2002
As you can see, the query is quite simple, however, I have to run this query separately for each different table and then manually copy and paste the results into a spreadsheet!
I now need to build a query that will pull the data from all 6 tables and return the results in one big query. Can you guys help!?
Let me know if you need any further details about the query above.
Any help greatly appreciated. I'm chin deep in this one.