nenad-zivkovic (7/15/2013)
You haven't read it carefully. It says: "If a table name is aliased, only the alias name can be used to qualify its columns in the ORDER BY clause."So this will not work:
select a from test t
order by test.a
+1
But this applies for the whole query, not only to the ORDER BY clause. It's funny, though, that if you alias the column, both names can be used (original & alias) in the ORDER BY clause
Create table #test(a int)
insert into #test values (null)
insert into #test values (2)
insert into #test values (3)
insert into #test values (1)
insert into #test values (null)
-- Will work
select a as col1 from #test as t
order by col1 -- ORDER BY alias
select a as col1 from #test as t
order by a -- ORDER BY column name
-- Will NOT work
select #test.a as col1 from #test as t
order by col1
select a as col1 from #test as t
order by #test.a
drop table #test
Cheers