Search This Blog

November 08, 2007

How to display "ALL" or Country name at the top

There are many scenarios where you need to display "ALL" or "Select ALL" or a particular value at the top in a drop down list. Most of the people hard code the values in the UI. You can display this value from the backend also.

For example if you want to display the country "USA" at the top and the rest of countries in sort order you can use the following statement. Assuming COUNTRY information is stored in Country table.

SELECT "USA" AS CountryName, 0 AS SortColumn
UNION
SELECT CountryName, 1 AS SortColumn FROM Country ORDER BY SortColumn, CountryName

or

SELECT CountryName FROM Country ORDER BY (CASE WHEN CountryName='USA' THEN CHAR(0) ELSE CountryName End)

You can use this to display the product names, category names.....

No comments: