jersoft
jersoft

Reputation: 478

How to sort record inside views in SQL Server 2008

I'm having a problem with regards in sorting inside the View on SQL Server 2008. Please refer to the Image below.

enter image description here

as you can see in the designer, i've sort the Column SeqID (Int Datatype), but when i select the View, the the Sorted Column seems not working.

enter image description here

Any suggestions?

Upvotes: 0

Views: 263

Answers (2)

Raj
Raj

Reputation: 10853

Why do you need to sort a view? A view is like a table so you sort it when you select from it:

select * from V_APDoc order by SeqID DESC;

Upvotes: 3

Adriaan Stander
Adriaan Stander

Reputation: 166476

From CREATE VIEW (Transact-SQL)

The ORDER BY clause is used only to determine the rows that are returned by the TOP or OFFSET clause in the view definition. The ORDER BY clause does not guarantee ordered results when the view is queried, unless ORDER BY is also specified in the query itself.

From the quote, you should always specifiy the SORT ORDER if you wish to guarantee the ordered results.

Upvotes: 1

Related Questions