I have a view in SQL Server 2005 that is sorted. When I import to Excel, it
comes in not sorted. Where the problem on this? I also posted on Excel Gen
Questions. Thanks.
A view isn't sorted, as a table isn't. What you need to do is to have ORDER BY when you read *from*
the view. Even if you have ORDER BY and TOP 100 PERCENT in the view definition, SQL Server will
ignore it. Since ... a view isn't sorted.

Signature
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://sqlblog.com/blogs/tibor_karaszi
>I have a view in SQL Server 2005 that is sorted. When I import to Excel, it
> comes in not sorted. Where the problem on this? I also posted on Excel Gen
> Questions. Thanks.
Pat M - City of Reno - 31 Aug 2007 23:22 GMT
this is great...I will do so...I really appreciate the help. I didn't know a
view was never sorted.

Signature
Regards,
Pat
> A view isn't sorted, as a table isn't. What you need to do is to have ORDER BY when you read *from*
> the view. Even if you have ORDER BY and TOP 100 PERCENT in the view definition, SQL Server will
[quoted text clipped - 3 lines]
> > comes in not sorted. Where the problem on this? I also posted on Excel Gen
> > Questions. Thanks.
Pat M - City of Reno - 31 Aug 2007 23:28 GMT
Tibor:
When I look at options on the Import, Edit Query, all I see is
"LogosDB"."dbo"."vw_plm_CAFR1". Should I cut and paste the whole SQL
statement in that Window?

Signature
Regards,
Pat
> A view isn't sorted, as a table isn't. What you need to do is to have ORDER BY when you read *from*
> the view. Even if you have ORDER BY and TOP 100 PERCENT in the view definition, SQL Server will
[quoted text clipped - 3 lines]
> > comes in not sorted. Where the problem on this? I also posted on Excel Gen
> > Questions. Thanks.
Pat M - City of Reno - 31 Aug 2007 23:32 GMT
never mind Tibor, that worked...thanks a million!!!!!!
Pat

Signature
Regards,
Pat
> A view isn't sorted, as a table isn't. What you need to do is to have ORDER BY when you read *from*
> the view. Even if you have ORDER BY and TOP 100 PERCENT in the view definition, SQL Server will
[quoted text clipped - 3 lines]
> > comes in not sorted. Where the problem on this? I also posted on Excel Gen
> > Questions. Thanks.