I have a table [Officers] with column headings year, name, Pres, 1stVP, 2ndVP, Sec, Treas as column headings. I wish to construct a query with Lname, Fname and OfficeName as column headings where the result will contain only the current year's officers. I get the following error message as a result of the following union query:
Err:
the query:
I can save the odbc [officers] table as a local table [OfficersL] and the query works, so there doesn't seem to be a syntax problem.
Conversely, I can run the odbc version with the first SELECT and any one of the UNION SELECTs and it works. I have dumbed it down to:
and I get "ODBC - call failed", but it doesn't complain if I do:
The #1064 err code indicates reserved words--I cannot find any. Ideas? Thanks.
Err:
ODBC--call failed.
(MySQL][ODBC 5.1 Driver][mysqld-5.5.42-MariaDB-cll-lve]You have an error in your SQL syntax; check the manual that corresponds to your MariaDB Server version for the right syntax to use near 'UNION (SELECT {FN SUBSTRING('1stVP',({fn locate(" ","1stVP",1))+1),{fn len' at line 1 (#1064)
the query:
Code:
SELECT Mid$([pres],(InStr([pres]," "))+1) AS Lname, Left$([pres],(InStr([pres]," "))-1) AS Fname, "President" AS OfficeName
FROM Officers
WHERE (((InStr([officeryear],Year(Date())))>1))
UNION SELECT Mid$([1stVP],(InStr([1stVP]," "))+1), Left$([1stVP],(InStr([1stVP]," "))-1), "1stVP"
FROM Officers
WHERE (((InStr([officeryear],Year(Date())))>1))
UNION SELECT Mid$([2ndVP],(InStr([2ndVP]," "))+1), Left$([2ndVP],(InStr([2ndVP]," "))-1), "2ndVP"
FROM Officers
WHERE (((InStr([officeryear],Year(Date())))>1))
UNION SELECT Mid$([Sec],(InStr([Sec]," "))+1), Left$([Sec],(InStr([Sec]," "))-1), "Secretary"
FROM Officers
WHERE (((InStr([officeryear],Year(Date())))>1))
UNION SELECT Mid$([Tres],(InStr([Tres]," "))+1), Left$([Tres],(InStr([Tres]," "))-1), "Treasurer"
FROM Officers
WHERE (((InStr([officeryear],Year(Date())))>1));
I can save the odbc [officers] table as a local table [OfficersL] and the query works, so there doesn't seem to be a syntax problem.
Conversely, I can run the odbc version with the first SELECT and any one of the UNION SELECTs and it works. I have dumbed it down to:
Code:
SELECT pres AS Lname, "President" AS OName
FROM Officers
UNION
SELECT [1stVP],"1stVP"
FROM Officers
UNION
SELECT [2ndVP], "2ndVP"
FROM Officers
UNION
SELECT [Sec], "Secretary"
FROM Officers
UNION SELECT [Tres],"Tresurer"
FROM Officers;
Code:
SELECT pres AS Lname, "President" AS OName
FROM Officers
UNION SELECT [Tres],"Tresurer"
FROM Officers;
The #1064 err code indicates reserved words--I cannot find any. Ideas? Thanks.
Last edited: