[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Union Query - Need another pair of eyes

Posted on 2014-03-12
2
Medium Priority
?
192 Views
Last Modified: 2014-03-12
Getting  error after From?  What am I missing

INSERT INTO tblQuarterly_AchievedPct ( ContractNumber, Quarter, Tier1, Tier2, Tier3, Tier4, Tier5, Tier6 )
SELECT  tblContracts.ContractNumber, 1 AS Qtr, tblContracts.Q1T1, tblContracts.Q1T2, tblContracts.Q1T3, tblContracts.Q1T4, tblContracts.Q1T5, tblContracts.Q1T6
FROM tblContracts
Union All
SELECT  tblContracts.ContractNumber, 2 AS Qtr, tblContracts.Q2T1, tblContracts.Q2T2, tblContracts.Q2T3, tblContracts.Q2T4, tblContracts.Q2T5, tblContracts.Q2T6
FROM tblContracts
Union All
SELECT  tblContracts.ContractNumber, 3 AS Qtr, tblContracts.Q3T1, tblContracts.Q3T2, tblContracts.Q3T3, tblContracts.Q3T4, tblContracts.Q3T5, tblContracts.Q3T6
FROM tblContracts
Union All
SELECT  tblContracts.ContractNumber, 4 AS Qtr, tblContracts.Q4T1, tblContracts.Q4T2, tblContracts.Q4T3, tblContracts.Q4T4, tblContracts.Q4T5, tblContracts.Q4T6
FROM tblContracts

Open in new window

0
Comment
Question by:Karen Schaefer
2 Comments
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 2000 total points
ID: 39924119
try this

INSERT INTO tblQuarterly_AchievedPct ( ContractNumber, Quarter, Tier1, Tier2, Tier3, Tier4, Tier5, Tier6 )
SELECT A.ContractNumber, A.Qtr, A.Q1T1, A.Q1T2, A.Q1T3, A.Q1T4, A.Q1T5, A.Q1T6
From
(
SELECT  tblContracts.ContractNumber, 1 AS Qtr, tblContracts.Q1T1, tblContracts.Q1T2, tblContracts.Q1T3, tblContracts.Q1T4, tblContracts.Q1T5, tblContracts.Q1T6
FROM tblContracts
Union All
SELECT  tblContracts.ContractNumber, 2 AS Qtr, tblContracts.Q2T1, tblContracts.Q2T2, tblContracts.Q2T3, tblContracts.Q2T4, tblContracts.Q2T5, tblContracts.Q2T6
FROM tblContracts
Union All
SELECT  tblContracts.ContractNumber, 3 AS Qtr, tblContracts.Q3T1, tblContracts.Q3T2, tblContracts.Q3T3, tblContracts.Q3T4, tblContracts.Q3T5, tblContracts.Q3T6
FROM tblContracts
Union All
SELECT  tblContracts.ContractNumber, 4 AS Qtr, tblContracts.Q4T1, tblContracts.Q4T2, tblContracts.Q4T3, tblContracts.Q4T4, tblContracts.Q4T5, tblContracts.Q4T6
FROM tblContracts
) As A
0
 

Author Closing Comment

by:Karen Schaefer
ID: 39924228
thanks that did it.
0

Featured Post

Veeam and MySQL: How to Perform Backup & Recovery

MySQL and the MariaDB variant are among the most used databases in Linux environments, and many critical applications support their data on them. Watch this recorded webinar to find out how Veeam Backup & Replication allows you to get consistent backups of MySQL databases.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
Suggested Courses

825 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question