B
Brett
Hi all:
I have a SELECT query I'm having problems with (returns the error
message "you tried to execute a query that does not include the
specified expression X as part of an aggregate function").
Here's the SQL (yes, I realize this is a bad database design, but I
got this from a client, so I'm forced to work with it):
SELECT ID_SK,SPECIALTY,ADOPTER_FLAG,TYPE,STATUS,STATE,TERRITORY_ID,
(Nz(NRX_8_11_06,0)+Nz(NRX_8_18_06,0)+Nz(NRX_8_25_06,0)+Nz(NRX_9_01_06,0)+Nz(NRX_9_08_06,0)+Nz(NRX_9_15_06,0)+Nz(NRX_9_22_06,0)+Nz(NRX_9_29_06,0)
+Nz(NRX_10_06_06,0)+Nz(NRX_10_13_06,0)+Nz(NRX_10_20_06,0)+Nz(NRX_10_27_06,0))
AS NRX_PRE,
(Nz(NRX_11_03_06,0)+Nz(NRX_11_10_06,0)+Nz(NRX_11_17_06,0)+Nz(NRX_11_24_06,0)+Nz(NRX_12_1_06,0)+Nz(NRX_12_8_06,0)+Nz(NRX_12_15_06,0)+Nz(NRX_12_22_06,0)
+Nz(NRX_12_29_06,0)+Nz(NRX_1_05_07,0)+Nz(NRX_1_12_07,0)+Nz(NRX_1_19_07,0))
AS NRX_POST,
(Nz(PT_8_11_06,0)+Nz(PT_8_18_06,0)+Nz(PT_8_25_06,0)+Nz(PT_9_01_06,0)+Nz(PT_9_08_06,0)+Nz(PT_9_15_06,0)+Nz(PT_9_22_06,0)+Nz(PT_9_29_06,0)+
Nz(PT_10_06_06,0)+Nz(PT_10_13_06,0)+Nz(PT_10_20_06,0)+Nz(PT_10_27_06,0))
AS CALLS_PRE,
(Nz(PT_11_03_06,0)+Nz(PT_11_10_06,0)+Nz(PT_11_17_06,0)+Nz(PT_11_24_06,0)+Nz(PT_12_01_06,0)+Nz(PT_12_08_06,0)+Nz(PT_12_15_06,0)+Nz(PT_12_22_06,0)+
Nz(PT_12_29_06,0)+Nz(PT_1_05_07,0)+Nz(PT_1_12_07,0)+Nz(PT_1_19_07,0))
AS CALLS_POST
FROM SecondStepResults
WHERE ( (STATUS="Active") AND
SPECIALTY IN ("Cardiologist","Interventional Cardiology","Internal
Medicine","Nurse Practitioner","Card Office - NP","FP/GP") AND
STATE IN
("NY","PA","NJ","CT","MA","RI","GA","SC","FL","TN","IN","KY","OH","MI","WI","IL","LA","MS","AL","TX","AR","KS","MO","NE","IA","CA","OR","HI","AZ","NV","UT","ID","WA","NM","WV","VA","NC","MC","DC"))
GROUP BY ID_SK,SPECIALTY,ADOPTER_FLAG,TYPE,STATUS,STATE,TERRITORY_ID
HAVING (NRX_PRE<3 AND NRX_POST<5 AND CALLS_PRE<12 AND CALLS_POST<12);
This is failing on the sum across fields expressions (Nz(...), i.e.,
in the error message mentioned above, X is the expression summing
across fields). I was under the impression that only the non-function
fields needed to be included in the Group By clause.
I've also tried creating an intermediate query without the WHERE and
HAVING clauses and get the same error, so it is something about the
summing across field statement that it doesn't like.
Any idea what is wrong in the above SQL?
Thanks,
Brett
I have a SELECT query I'm having problems with (returns the error
message "you tried to execute a query that does not include the
specified expression X as part of an aggregate function").
Here's the SQL (yes, I realize this is a bad database design, but I
got this from a client, so I'm forced to work with it):
SELECT ID_SK,SPECIALTY,ADOPTER_FLAG,TYPE,STATUS,STATE,TERRITORY_ID,
(Nz(NRX_8_11_06,0)+Nz(NRX_8_18_06,0)+Nz(NRX_8_25_06,0)+Nz(NRX_9_01_06,0)+Nz(NRX_9_08_06,0)+Nz(NRX_9_15_06,0)+Nz(NRX_9_22_06,0)+Nz(NRX_9_29_06,0)
+Nz(NRX_10_06_06,0)+Nz(NRX_10_13_06,0)+Nz(NRX_10_20_06,0)+Nz(NRX_10_27_06,0))
AS NRX_PRE,
(Nz(NRX_11_03_06,0)+Nz(NRX_11_10_06,0)+Nz(NRX_11_17_06,0)+Nz(NRX_11_24_06,0)+Nz(NRX_12_1_06,0)+Nz(NRX_12_8_06,0)+Nz(NRX_12_15_06,0)+Nz(NRX_12_22_06,0)
+Nz(NRX_12_29_06,0)+Nz(NRX_1_05_07,0)+Nz(NRX_1_12_07,0)+Nz(NRX_1_19_07,0))
AS NRX_POST,
(Nz(PT_8_11_06,0)+Nz(PT_8_18_06,0)+Nz(PT_8_25_06,0)+Nz(PT_9_01_06,0)+Nz(PT_9_08_06,0)+Nz(PT_9_15_06,0)+Nz(PT_9_22_06,0)+Nz(PT_9_29_06,0)+
Nz(PT_10_06_06,0)+Nz(PT_10_13_06,0)+Nz(PT_10_20_06,0)+Nz(PT_10_27_06,0))
AS CALLS_PRE,
(Nz(PT_11_03_06,0)+Nz(PT_11_10_06,0)+Nz(PT_11_17_06,0)+Nz(PT_11_24_06,0)+Nz(PT_12_01_06,0)+Nz(PT_12_08_06,0)+Nz(PT_12_15_06,0)+Nz(PT_12_22_06,0)+
Nz(PT_12_29_06,0)+Nz(PT_1_05_07,0)+Nz(PT_1_12_07,0)+Nz(PT_1_19_07,0))
AS CALLS_POST
FROM SecondStepResults
WHERE ( (STATUS="Active") AND
SPECIALTY IN ("Cardiologist","Interventional Cardiology","Internal
Medicine","Nurse Practitioner","Card Office - NP","FP/GP") AND
STATE IN
("NY","PA","NJ","CT","MA","RI","GA","SC","FL","TN","IN","KY","OH","MI","WI","IL","LA","MS","AL","TX","AR","KS","MO","NE","IA","CA","OR","HI","AZ","NV","UT","ID","WA","NM","WV","VA","NC","MC","DC"))
GROUP BY ID_SK,SPECIALTY,ADOPTER_FLAG,TYPE,STATUS,STATE,TERRITORY_ID
HAVING (NRX_PRE<3 AND NRX_POST<5 AND CALLS_PRE<12 AND CALLS_POST<12);
This is failing on the sum across fields expressions (Nz(...), i.e.,
in the error message mentioned above, X is the expression summing
across fields). I was under the impression that only the non-function
fields needed to be included in the Group By clause.
I've also tried creating an intermediate query without the WHERE and
HAVING clauses and get the same error, so it is something about the
summing across field statement that it doesn't like.
Any idea what is wrong in the above SQL?
Thanks,
Brett