Apache OpenOffice (AOO) Bugzilla – Issue 66837
HSQL improvement: Cannot use column aliases as variables in queries
Last modified: 2023-12-10 13:23:44 UTC
It is not possible to, say, to assemble a date string AS "dte" and then use it in a function, e.g. MONTHNAME("dte")
Not sure which database engine you are working with, but if it is the embedded HSQL then this may be a limitation of the engine. If I have a table of school information with address fields and try to run this statement directly in HSQL ( SQL direct mode TRUE ) HSQL will generate a column not found error: SELECT "ID", "NAME", CONCAT(CONCAT("ADD1", ' ' ), "ADD2") AS "ADDRESS" , SUBSTRING( "ADDRESS", 1, 3 ) AS "STREET NUM" FROM "SCHOOLS" However, if I change this to a sub-select it will run as expected - I presume since the outer select statement now has visibility of the aliased column name: SELECT "ID", "NAME", "ADDRESS", SUBSTRING( "ADDRESS", 1, 3 ) AS "STREET NUM" FROM ( SELECT "ID", "NAME", CONCAT(CONCAT("ADD1", ' ' ), "ADD2") AS "ADDRESS" FROM "SCHOOLS" ) The problem with this, at the moment, is that this type of query will not work properyly with the form or report wizard. Should that change, then I would not see why Base wouldn't be adequate as The same holds true for MySQL by the way. This query will fail: SELECT `EmployeeID`, `DepartmentID`, CONCAT( `FirstName`, ' ' , `MiddleName`, ' ', `LastName`) AS FULL_NAME, SUBSTR( `FULL_NAME`, 1, 3 ) AS FOO FROM `openoffice`.`employees` `employees` This will run as expected: SELECT `EmployeeID`, `DepartmentID`, `FULL_NAME`, SUBSTR( `FULL_NAME`, 1, 3 ) AS FOO FROM ( SELECT `EmployeeID`, `DepartmentID`, CONCAT( `FirstName`, ' ' , `MiddleName`, ' ', `LastName`) AS FULL_NAME FROM `openoffice`.`employees` `employees` ) TMP1
Yes, that is the problem. I have got a workaround, but like yours, it is clumsy. I am using the inbuilt HSQL database. Previously I have used access in which using column aliases as variables is straightforward and very convenient.
this is a valid feature enhancement => send further to the requirement team
Already reported with Issue #49185 - Queries can't call macro functions If you want real date functions, HSQLDB engine must be update to 2.x : #121837 *** This issue has been marked as a duplicate of issue 121837 ***