Click here to Skip to main content
15,891,204 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more: , +
Good Evening ,

I have large number of data in sqlserver 2005 database , and

How to write a query in sqlserver 2005, to display the records alphabets wise.(a-z)

Thanx Experts.
Posted

You need to use the order by clause to order records in a query.
 
Share this answer
 
Comments
k@ran 17-Jul-12 6:07am    
select * from employee to view record and
select * from employee order by emp_name asc|desc
SQL
SELECT EMPLOYEE_NAME FROM EMPLOYEE_MASTER ORDER BY EMPLOYEE_NAME ASC
 
Share this answer
 
Use of "ORDER BY" in t-sql sorts your records. You can read more about it here http://www.w3schools.com/sql/sql_orderby.asp[^]

SQL
SELECT * FROM [Table] ORDER BY [Column] ASC

Or the other way
SQL
SELECT * FROM [Table] ORDER BY [Column] DESC



If you have a large number of records you may consider indexing that column. http://www.sql-server-performance.com/2007/optimizing-indexes-general/[^]
 
Share this answer
 
Comments
Ranjith Reddy CSE 17-Jul-12 6:25am    
SqlDataAdapter dad3 = new SqlDataAdapter("select ClearanceNumber, CodeFlightId, DateLastChange, DateValidFrom,"
+ "DateValidTo, ReservationNo, AircraftType, CityCode, Days from Flight order by CodeFlightId", con);

Please check this Query, I need Alphabet wise.

Please help, Please correct this Query
StianSandberg 17-Jul-12 6:37am    
your query "SELECT ClearanceNumber, CodeFlightId, DateLastChange, DateValidFrom,DateValidTo, ReservationNo, AircraftType, CityCode, Days
FROM Flight
ORDER BY CodeFlightId"
will return all data ordered by CodeFlightId ascending. Are you downwoting two perfectly correct answers here?
Ranjith Reddy CSE 17-Jul-12 6:28am    
This Query am using in dropdown list.....when i select sort by codeflightid it must display alphabet wise.

Please help , above is my query, am using that query in dropdownlist.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900