Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

SQL Server ORDER BY bug?

0 views
Skip to first unread message

Mario Menger

unread,
Jun 17, 2004, 9:29:52 AM6/17/04
to
Running the following query (on SQL Server 2000 SP3a)

SELECT
[Name] AS Blop,
Id AS [Name]
FROM
SYSOBJECTS
ORDER BY
SYSOBJECTS.[Name]

results in a set of records ordered by the Id column (aliased as Name),
surely it should order them by SYSOBJECTS.[Name] as I tell it to?

Is there any good reason why it would ignore the table name?

Cheers,
Rsa


David Portas

unread,
Jun 17, 2004, 10:13:07 AM6/17/04
to
This is a known bug/feature. Because an ORDER BY statement can refer to
aliased columns as well as base table columns the column name is used
without reference to the alias (in fact the alias can be a non-existent one
and it won't generate an error).

The exception is where the specified column name is ambiguous (the same name
from more than one base table). Then the correct alias must be used.

--
David Portas
SQL Server MVP
--


0 new messages