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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Weird Behaviour with View Editing Vs Opening

Author  Topic 

velnias2010
Posting Yak Master

125 Posts

Posted - 2011-06-08 : 09:12:38
So I created this view

SELECT TOP (100) PERCENT dbo.tblReports.ID, dbo.tblProducts.Name AS Product, dbo.tblProducts.ID AS productID, dbo.tblReports.Date, dbo.tblReports.Title,
dbo.tblReports.FileName, dbo.tblReports.[Document], dbo.tblAccess.CustomerID, dbo.tblReports.WeekYear, dbo.tblReports.Week, dbo.tblReports.Week2
FROM dbo.tblAccess INNER JOIN
dbo.tblProducts ON dbo.tblAccess.ProductID = dbo.tblProducts.ID INNER JOIN
dbo.tblReports ON dbo.tblAccess.ProductID = dbo.tblReports.ProductID
ORDER BY dbo.tblReports.Date DESC, dbo.tblReports.Week DESC, dbo.tblReports.Week2 DESC, Product, dbo.tblReports.ProductID

And when im editing it and running it works fine.

But then when I click save and right click on the view and click on open view it seems to loose the ordering which I specified above.

Any Reason ?

Lumbago
Norsk Yak Master

3271 Posts

Posted - 2011-06-08 : 09:21:06
ORDER BY is generally not supported in views so the view designer probably removes it for you even though you have specified the TOP keyword. Views can be used in joins and such and the order would be messed up, so you should ALWAYS use ORDER BY in your final query if you want a specific order. Nothing else will guarantee that data is ordered when it's retured by the database engine.

- Lumbago
My blog-> http://thefirstsql.com/2011/02/07/regular-expressions-advanced-string-matching-and-new-split-function-sql-server-2008-r2/
Go to Top of Page

velnias2010
Posting Yak Master

125 Posts

Posted - 2011-06-08 : 09:33:19
OK Grand Thanks
Go to Top of Page
   

- Advertisement -