Advertisement

07.17.2008 at 06:14AM PDT, ID: 23573054
[x]
Attachment Details

Whats wrong with my union query? Its not very long... Getting error, "The expression is typed incorrectly, or is too complex to be evaluated..."

Asked by JA67 in Microsoft Access Database, SQL Query Syntax

Tags: Microsoft, Access, 2007

Hello,

This first example works and does not give any errors, but the second one gives the error denoted in the question title.

It's the addition of the last (bottom most) query in the 2nd example that is generating the error. I can run the last query by itself and it runs without error, but when I tack it on to the bottom of the 1rst example, I get the error.

THANK YOU!!!
JA67



Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
****************************************************************************
1rst EXAMPLE:
**************************************
 
SELECT DeptName, sum(ThisMonthRec) AS ReceivedThisMonth, sum(RollingAvg) AS RollingAverage, sum(YearToDatTtl) AS YearToDateRec
FROM 
 
(SELECT
request_dept_nm AS DeptName, 
Count(request_dept_nm) AS ThisMonthRec,
NULL AS RollingAvg,
NULL AS YearToDatTtl
FROM request_fact
WHERE requested_dt BETWEEN Forms!frmRSS_TtlsByFrq!cmbMonthBeg AND Forms!frmRSS_TtlsByFrq!cmbMonthEnd
GROUP BY request_dept_nm
 
UNION ALL
 
SELECT
request_dept_nm AS DeptName, 
NULL AS ThisMonthRec,
Round((Count(request_dept_nm))/12) As RollingAvg,
NULL AS YearToDatTtl
FROM request_fact
WHERE requested_dt  BETWEEN  DateDiff("m", -12, Forms!frmRSS_TtlsByFrq!cmbMonthEnd) AND  Forms!frmRSS_TtlsByFrq!cmbMonthEnd
GROUP BY request_dept_nm)
 
GROUP BY DeptName;
 
****************************************************************************
2nd EXAMPLE:
**************************************
SELECT DeptName, sum(ThisMonthRec) AS ReceivedThisMonth, sum(RollingAvg) AS RollingAverage, sum(YearToDatTtl) AS YearToDateRec
FROM 
 
(SELECT
request_dept_nm AS DeptName, 
Count(request_dept_nm) AS ThisMonthRec,
NULL AS RollingAvg,
NULL AS YearToDatTtl
FROM request_fact
WHERE requested_dt BETWEEN Forms!frmRSS_TtlsByFrq!cmbMonthBeg AND Forms!frmRSS_TtlsByFrq!cmbMonthEnd
GROUP BY request_dept_nm
 
UNION ALL
 
SELECT
request_dept_nm AS DeptName, 
NULL AS ThisMonthRec,
Round((Count(request_dept_nm))/12) As RollingAvg,
NULL AS YearToDatTtl
FROM request_fact
WHERE requested_dt  BETWEEN  DateDiff("m", -12, Forms!frmRSS_TtlsByFrq!cmbMonthEnd) AND  Forms!frmRSS_TtlsByFrq!cmbMonthEnd
GROUP BY request_dept_nm
 
 
UNION ALL
 
SELECT
request_dept_nm AS DeptName, 
NULL AS ThisMonthRec,
NULL As RollingAvg,
Count(request_dept_nm) As YearToDatTtl
FROM request_fact
WHERE requested_dt BETWEEN #06/01/2008# AND #06/30/2008#
GROUP BY request_dept_nm)
 
GROUP BY DeptName;
[+][-]07.17.2008 at 06:33AM PDT, ID: 22025219

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.17.2008 at 06:38AM PDT, ID: 22025272

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.17.2008 at 06:41AM PDT, ID: 22025310

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.17.2008 at 07:03AM PDT, ID: 22025543

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]07.17.2008 at 07:05AM PDT, ID: 22025567

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Microsoft Access Database, SQL Query Syntax
Tags: Microsoft, Access, 2007
Sign Up Now!
Solution Provided By: peter57r
Participating Experts: 2
Solution Grade: A
 
 
[+][-]07.17.2008 at 07:47AM PDT, ID: 22025992

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.17.2008 at 08:01AM PDT, ID: 22026169

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.17.2008 at 08:42AM PDT, ID: 22026741

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.17.2008 at 08:48AM PDT, ID: 22026817

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.17.2008 at 10:14AM PDT, ID: 22027635

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.23.2008 at 11:57AM PDT, ID: 22072628

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628