I faced a small problem in using order by in views, Let me discuss the exact problem and hack to resolve this problem.
create table venkattable1(id int, val varchar(100))
insert into venkattable1(1,'Venkat')
insert into venkattable1(2,'Venkat')
insert into venkattable1(3,'Venkat')
create view venkatview
as
select * from venkattable1 order by id
I got the below error,
"The ORDER BY clause is invalid in views, inline functions, derived tables, subqueries, and common table expressions, unless TOP or FOR XML is also specified."
It shows that, we can't use order by clause on the view, I've tried with Top clause in the above statement,
create view venkatview
as
select top 10 * from venkattable1 order by id
It's working fine. Please check the bleow URL for more details related to this problem.
http://forums.microsoft.com/msdn/ShowPost.aspx?PostID=3908414&SiteID=1
No comments:
Post a Comment