SQL Server follows the below processing order, when you run a SELECT query.Read more about Processing Order of SELECT query
Logical Processing Order of the SELECT statement
The following steps show the logical processing order, or binding order, for a
SELECT statement. This order determines when the objects defined in
one step are made available to the clauses in subsequent steps. For
example, if the query processor can bind to (access) the tables or
views defined in the FROM clause, these objects and their columns are
made available to all subsequent steps. Conversely, because the SELECT
clause is step 8, any column aliases or derived columns defined in
that clause cannot be referenced by preceding clauses. However, they
can be referenced by subsequent clauses such as the ORDER BY clause.
The actual physical execution of the statement is determined by the
query processor and the order may vary from this list.
- FROM
- ON
- JOIN
- WHERE
- GROUP BY
- WITH CUBE or WITH ROLLUP
- HAVING
- SELECT
- DISTINCT
- ORDER BY
- TOP
Your Alias is coming in the SELECT stage 8 and so, it cannot be referred in the preceding stage 4(WHERE clause). If you want to reference alias in your WHERE clause, the alias should be part of the FROM clause(Stage 1), which is preceding WHERE clause(stage 4). What you can do is, have a subquery in the FROM clause to get alias as part of the result and use it subsequently in the WHERE clause.
SELECT top(1) APName
FROM (SELECT firstname+' '+lastname AS APName, CustomerNr From ansprech) AS c
WHERE customernr = 10205 and APName LIKE '%Max Example';