cancel
Showing results for 
Search instead for 
Did you mean: 

Is this a real error? Definition for alias '%1' must appear before its first reference

Breck_Carter
Participant
2,344

Since this query works in 7.0.3, 8.0.3, 11.0.1 and 12.0.1 (and I am sure many other versions)...

SELECT x + 1, 1 AS x;

x+1,x
2,1

...what is the meaning of this 12.0.1 Help topic?

Definition for alias '%1' must appear before its first reference

Error constant  SQLE_ALIAS_NOT_YET_DEFINED
ODBC 2 state    37000
ODBC 3 state    ERROR
Parameter 1 Name of the alias.
Severity    15
SQLCODE         -831
SQLSTATE    42W61
Sybase error code   13837

An expression contains a reference to an alias, but the alias is defined later in the SELECT list. The alias definition must appear before its first reference.


Historical footnote...

What's New in SQL Anywhere Studio

6. What's New in Version 7.0.2

Behavior changes in version 7.0.2

Aliases must be defined before first reference

In earlier versions of SQL Anywhere, it was possible to refer to an alias in a SELECT list before the definition of the alias had appeared. An attempt to do so will now generate the error "Definition for alias alias-name must appear before its first reference". To prevent this error, the SELECT list must be re-ordered so that the alias definition appears before its first use.

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member

Thanks for pointing out this issue. The error is no longer valid since ~2001. The documentation will be fixed.