Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
Page47
Master Smack Fu Yak Hacker
2878 Posts |
Posted - 2002-09-11 : 13:43:15
|
quote: Syntax[ORDER BY {order_by_expression [ ASC | DESC ] } [,...n] ]Argumentsorder_by_expressionSpecifies a column on which to sort. A sort column can be specified as a name or column alias (which can be qualified by the table or view name), an expression, or a nonnegative integer representing the position of the name, alias, or expression in select list.
so ...select au_lname as lastnamefrom pubs.dbo.authorsorder by lastname and ...select au_lname as lastnamefrom pubs.dbo.authorsorder by case when 1=1 then au_lname end but not ...select au_lname as lastnamefrom pubs.dbo.authorsorder by case when 1=1 then lastname end ...what am I missing here? I have a select statement with a complex calculation as a column with an aliased name. I also have a case in my order by. But they won't play nice for me ...Jay White{0} |
|
|
robvolk
Most Valuable Yak
15732 Posts |
Posted - 2002-09-11 : 14:15:38
|
| It can only be the alias name, not an expression containing the alias name. The CASE expression doesn't know what the alias refers to. |
 |
|
|
Page47
Master Smack Fu Yak Hacker
2878 Posts |
Posted - 2002-09-12 : 06:13:58
|
Seems that way ... its just not fair ...This does it though ...select * from(select au_lname as lastnamefrom pubs.dbo.authors) aorder by case when 1=1 then lastname end Jay White{0} |
 |
|
|
|
|
|