Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with Syntax error on Union Query 1

Status
Not open for further replies.

kentwoodjean

Technical User
Oct 19, 2002
376
US
Getting a error on my SQl statement of my Union query. I am fairly new at them and am getting the error “Syntax error in FROM Clause”. The right bracket following = q3.[Closed Dt]) LEFT JOIN is what is highlighted. Removal of the bracket messes up other items. I’m sure it cannot be far off so any help would be appreciated.

Here is my SQL:

SELECT q.[Closed Dt] AS [Closed Date], q.[CountOfClosed Dt] AS TotCloses, Sum(q2.[CountOfClosed Dt]) AS [21 days], Sum(q3.[CountOfClosed Dt]) AS [30 days], Sum(q6.[CountOfClosed Dt]) AS [60 days], Sum(q61.[CountOfClosed Dt]) AS [61 days]
FROM ([Countof Closed Date] AS q LEFT JOIN [Closes 0-21] AS q2 ON q.[Closed Dt] = q2.[Closed Dt]) LEFT JOIN [Close 22-30] AS q3 ON q.[Closed Dt] = q3.[Closed Dt]) LEFT JOIN [Close 31-60] AS q6 ON q.[Closed Dt] = q6.[Closed Dt]) LEFT JOIN [Close 60+] AS q61 ON q.[Closed Dt] = q61.[Closed Dt]
GROUP BY q.[Closed Dt], q.[CountOfClosed Dt];
 
I don't know whether this gives you what you are after but you can try:

FROM (((([Countof Closed Date] AS q LEFT JOIN [Closes 0-21] AS q2 ON q.[Closed Dt] = q2.[Closed Dt]) LEFT JOIN[Close 22-30] AS q3 ON q.[Closed Dt] = q3.[Closed Dt]) LEFT JOIN [Close 31-60] AS q6 ON q.[Closed Dt] = q6.[Closed Dt]) LEFT JOIN [Close 60+] AS q61 ON q.[Closed Dt] = q61.[Closed Dt])

By the way, this is not a Union query. Union queries involve the word Union and are used to create a single recordset from two or more sources (combining two tables with the same structure into a single recordset, for example)
 
Thanks for the clarifcation regarding type of query. Still learning. Not sure as to whether it will work as now I am getting another error, "Enter Parameter Value q2.CountOfClosed Dt". This box is then repeated for q3,q6, and q61. Any thoughts here?
 
The implication of that message is that the input tables or queries q2, q3 and q6 don't have fields named [CountOfClosed Dt] so SQL assumes that they must be user supplied paramaters. Check the actual field names in your input tables or queries.
 
You were right. I had 2 sets of queries that I was using for testing and I pulled the wrong set. It works perfectly now and looks great. Thanks for your direction.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top