Tuesday, February 14, 2012

Display database column in alphabetical order

Hello

I know how I can display a list of names in alphebetical order on my website:

Select L as [Last Name]

From Name_CatE
Where Education = 'yes'
Order By
LName ASC

However, to make things a little more orginised I would like to view my database table column in alphabetical order also, but ithie code does not work within my database.

What do I need to change in the following code, to view my database table column in a-z order?

SELECT LName FROM Name_CatE
ORDER BY LName ASC

Thanks

Lynn

Are you asking how to physically sort the rows in the table in LName order? If so, you could use a clustered index. But typically this is not a good idea for fields like LName, which could have many duplicate values. Check Books Online for details about the implications of doing this, particularly on performance.

But do you really need this? Is it just a preference, or do you have a solid business requirement for this? If it's just a preference, don't do it. that's what the ORDER BY clause is for.

Don

No comments:

Post a Comment