Search This Blog

Friday, August 10, 2007

Order by Inside View

Can Order by be used inside a view

Create View vw_Emp_Salary
As
Select Emp_ID,Emp_Name,Emp_Sal from Emp_Salary


Suppose I want to order by employees who get more salary first,then view definition would look like:

Create View vw_Emp_Salary
As
Select Emp_ID,Emp_Name,Emp_Sal from Emp_Salary
ORDER by Emp_Sal desc

But This gives a error when compiled saying "Order By cannot be used unless TOP is specified",but if I use TOP wont my resultset of rows get reduced.So the query would be

Create View vw_Emp_Salary
As
Select TOP 100 PERCENT Emp_ID,Emp_Name,Emp_Sal from Emp_Salary
ORDER by Emp_Sal desc

No comments: