Order by Ordinal ?

Last Post 24 Sep 2007 06:41 AM by gilou28. 3 Replies.
AddThis - Bookmarking and Sharing Button Printer Friendly
  •  
  •  
  •  
  •  
  •  
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages
gilou28
New Member
New Member

--
13 Sep 2007 11:45 AM
I have a select statement that use the following syntax:

Select ...
from #t
order by Ordinal

Ordinal is NOT a column of the temporary table #t

I'm trying to find reference on that syntax, but could not find anything in BOL, no luck.

Can anyone point me in the right direction for that syntax ?

Thanks.
gilou28
New Member
New Member

--
14 Sep 2007 05:30 AM
Hi and thanks.

Yes it does work when it's called, but I'm unable to reproduce it since the select is based on a local temporary table. When I try to reproduce, the syntax fails.

In one SP I see that this column is updated, but I could not find where the table was created and I think it's created implicitely using a insert into #t select... construct. The thing is that Ordinal is never specified in the 7 different places that issues the insert into #t.

The creation might be explicit and is done by the client in a direct statement (not in a SP).

Analysis Services is not in the picture.

Thanks again, at least I'm sure it's not a TSQL pseudo column.
SQLUSA
New Member
New Member

--
21 Sep 2007 02:44 AM
It is better T-SQL coding if you assign an alias to the column and ORDER BY the alias.

Note: the alias cannot be used in a GROUP BY, but can be used in ORDER BY ( i always wondered about this).

Kalman Toth, Database Architect
SQL Server 2005 Training - http://www.sqlusa.com/order2005grandprix
gilou28
New Member
New Member

--
24 Sep 2007 06:41 AM
Identity... makes sense... I never taught of using that in a temp table....

Thanks.
You are not authorized to post a reply.

Acceptable Use Policy