C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !




Sort records in Database Views


Posted Date: 22 Apr 2007    Resource Type: Code Snippets    Category: SQL

Posted By: Vadivel Mohanakrishnan       Member Level: Diamond
Rating:     Points: 10



Sorting will not work by default in database Views. Here is a work around to sort the records in a database view.

As we all know, for sorting the values while fetching records we need to make use of ORDER BY clause.

That said, would the below code snippet work?



Create View SampleView
As
Select Sno, Firstname from employeeTable ORDER BY Firstname



Nope it won't!!!

The work around is, we need to use "TOP 100 PERCENT" in our query if we want to use ORDER BY clause in a View (or) a Subquery (or) a derived table. (BTW this is possible from SQL Server 7+.).

See below the modified code snippet:



Create View SampleView
As
Select TOP 100 PERCENT Sno, Firstname employeeTable ORDER BY Firstname





Responses

Author: Kapil Dhawan    17 Jun 2008Member Level: Gold   Points : 2
Hello
Nice piece of code
Thanks for sharing your knowledge with us.
I hope to see more good code from your side
This code will help lots of guys
Thanks to you
Regards,
Kapil



Feedbacks      
Popular Tags   What are tags ?   Search Tags  
(No tags found.)

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: How to find whether a database column is identity or not?
Previous Resource: Read the status of SQL Server Agent jobs
Return to Discussion Resource Index
Post New Resource
Category: SQL


Post resources and earn money!
 
Related Resources



dotNet Slackers   BizTalk Adaptors    Web Design

web conferencing services

Contact Us    Privacy Policy    Terms Of Use