Someone sent me a query that contained the following:
Are you allowed to use the calculated columns in other calculated columns? Are you guaranteed that it fills in the values in the select column order? The select works, but I'm not sure I trust the data.
asked 18 Jan '10, 17:00
The short answer is yes. The server will evaluate the various expressions in the correct dependency order, if dependencies between them exist. If at build time a dependency cycle is encountered, the statement will get an error.
Hence this statement:
select EmployeeID as X, X + X as Y from Employees
works, but this statement
select EmployeeID as X, X as EmployeeID from Employees
gets SQLCODE -831.
answered 18 Jan '10, 21:23
In addition to what Glenn said... SQL Anywhere is like a spreadsheet, it doesn't matter what order the expressions are in the cells, er, select list.
Plus, you can refer to them in WHERE clauses, ORDER BY, etc...
SELECT y + x AS z, x + 1 AS y, 47 * 52 AS x WHERE z > y ORDER BY x, y, z;
answered 19 Jan '10, 10:10