Search

Categories

Tags

CASE within ORDER BY

Customers like to add comments to drop downs.  The AppendDataBoundItems property is available, which appends data bound items to statically declared list items from the Items collection.  This would bury the hard-coded text within the control and could be confusing as to where it is coming from.  Another way would be to include them in the result set,

SELECT TOP (100) PERCENT Id, Description
FROM (SELECT Id, Description
       FROM a INNER JOIN b ON b.Id = a.Id
      UNION
      SELECT -1 AS Id, 'Select...' AS Description
      UNION
      SELECT 0 AS Id, 'Add...' AS Description
      WHERE (@ShowAdd = 1)) AS c
ORDER BY CASE WHEN Id <= 1 THEN Description END DESC, CASE WHEN Id > 1 THEN Description END

The Id values are arbitrary, however, should not collide with Ids from the table.  The order by puts them at the top of the list where they are easily seen.

October 5, 2007 01:17 by jk
E-mail | Permalink | Comments (1) | Comment RSSRSS comment feed

Comments

Add comment


(Will show your Gravatar icon)

  Country flag

biuquote
  • Comment
  • Preview
Loading