SQL Server view doesn't follow ORDER BY Clause

Hi

I have a table with 2 columns in SQL Server 2005:
- a currency number from a host system, which is a 3-digit number stored as text and is the PK of the table
- the 3-chararcter ISO code for the currency

I need to view this table "the other way around" with:
- the ISO code as the first column, sorted in ascending sequence
- the corresponding currency number as the second column

So I defined a corresponding view, for which the SQL looks perfect.

But when I open the view, it is still sorted by currency number (second column, on which I have NO sorting defined) although the SQL says ORDER BY ISO (first column) !!!

Is this a bug or a feature ?

Bernard
LVL 1
bthouinAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Lee SavidgeCommented:
You don't put the ORDER BY in the view. You leave the view unordered and when you select from it then you can order the output.
0
Randy PooleCommented:
Just do select * from yourview order by 1
0
Bhavesh ShahLead AnalysistCommented:
hi,

Ideal scenario, your view should work.
Please share your view text and result.
0
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

bthouinAuthor Commented:
I can't. This query (and more to follow) are used in an Excel spreadsheet where I bind them over the Data / Connections menus, the result being refreshed on Excel startup and stored in a sheet which is use as data validation source. Using the menus and defining the connection, there is NO WAY for me to indicate a sort /order by clause, so I'm stuck with the view as it is defined in SQL Server, which is plain wrong.

Anyway, why would the view offer a sort capability if it's not to be used ? And since when is a SQL statement with an ORDER BY clause not executed properly by SQL Server ? If I use such a clause from any application (Access, .Net, whatever) calling SQL Server, the latter always follows the ORDER BY. So why doesn't it follow the ORDER BY on its own view-based SQL statements ?
0
Guy Hengel [angelIII / a3]Billing EngineerCommented:
as from SQL 2008, ORDER BY will not even be allowed inside a view (unless you also specify the TOP X or TOP X PERCENT for the SELECT)

so indeed, you cannot "define" the order by in a view anymore, this is a changed behavior.

note: I usually use stored procedures for querying data, there you can specify the order by without issues
0
Randy PooleCommented:
can you post a portion of your data, how your table is defined, and how your view is defined.
0
bthouinAuthor Commented:
Precision: my post was an answer to Lee's post (first post after my question).

I will post my view and result.
0
Randy PooleCommented:
After you create your connection, go to properties, definition, change command type from table to SQL and use select * from [whatever] order by 1
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
bthouinAuthor Commented:
Here the data and def's.
SQL-Server-view.docx
0
Randy PooleCommented:
Did you try modifying the connection per my last response?
0
bthouinAuthor Commented:
Hi Randy

Yes, I just did, and after some fumbling with the syntax it worked perfectly !

Thanks a lot guys for your help. Now I even know how to tweak data connection definitions in Excel, and I will NOT use any sorting in my SQL Server views...:-)

Bernard
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server 2005

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.