Error in syntax

  • Thread starter Thread starter Hugh self taught
  • Start date Start date
H

Hugh self taught

I was given this sql code but have the following error which I can't resolve..

"The SELECT Statement contains a reserved word or
an argument name that misspelled or missing, or the punctuation is incorrect"

SELECT Left([Register],2) AS Reg_2, IIF([Male] = -1, "Males", "Females") AS
Gender, Count([Male]) AS Quanity
FROM Competitors
GROUP BY Left([Register],2), IIF([Male] = -1, "Males", "Females")
UNION ALL SELECT "Total", IIF([Male] = -1, "Males", "Females") AS Gender,
Count([Male]) AS Quanity
GROUP BY "Total", IIF([Male] = -1, "Males", "Females");

I isolated it to the UNION ALL SELECT statements as the sql runs fine if I
remove the code from that select statement on. It must be something over my
head because the code is identical to that of the first SELECT statement
except for the "Total", parameter. Can anyone suggest what's wrong?
 
You second SELECT is missing its FROM clause; try adding

FROM Competitors

just before the last GROUP BY.



Vanderghast, Access MVP
 
Talk about "not see the wood for the trees"
Thanks a stack

Hugh

vanderghast said:
You second SELECT is missing its FROM clause; try adding

FROM Competitors

just before the last GROUP BY.



Vanderghast, Access MVP


Hugh self taught said:
I was given this sql code but have the following error which I can't
resolve..

"The SELECT Statement contains a reserved word or
an argument name that misspelled or missing, or the punctuation is
incorrect"

SELECT Left([Register],2) AS Reg_2, IIF([Male] = -1, "Males", "Females")
AS
Gender, Count([Male]) AS Quanity
FROM Competitors
GROUP BY Left([Register],2), IIF([Male] = -1, "Males", "Females")
UNION ALL SELECT "Total", IIF([Male] = -1, "Males", "Females") AS Gender,
Count([Male]) AS Quanity
GROUP BY "Total", IIF([Male] = -1, "Males", "Females");

I isolated it to the UNION ALL SELECT statements as the sql runs fine if I
remove the code from that select statement on. It must be something over
my
head because the code is identical to that of the first SELECT statement
except for the "Total", parameter. Can anyone suggest what's wrong?
 
Back
Top