Error in syntax

  • Thread starter Hugh self taught
  • 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?
 
V

vanderghast

You second SELECT is missing its FROM clause; try adding

FROM Competitors

just before the last GROUP BY.



Vanderghast, Access MVP
 
H

Hugh self taught

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?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top