Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2005-08-22 : 07:00:13
|
| Stephanie writes "I need to create a view that will be used to populate a HTML select control that will act as a filter on a HTML table. There is a field in the database where I need to find all of the distinct entries. These will be used as HTML options in the HTML select. I need to have the distinct entries be sorted ASC. In addition to this I need to have an option to let the user select "(None)" of the distinct entries. This option should be at the top of the list. The database has entries that are NULL, 'NULL'.The result should be a view that contains (for example):(None)4000500080009000...The following will almost get what I need, but I realize that ORDER BY cannot be used in a view or subquery. Plus, this code results in an extra '(None)'.SELECT CASE ISNULL(NULLIF(T.CODE,''),'NULL') WHEN 'NULL' THEN '(None)' ELSE T.CODE ENDFROM TABLE TGROUP BY T.CODEORDER BY T.CODEResults: (None)(None)4000500080009000..." |
|
|
AjarnMark
SQL Slashing Gunting Master
3246 Posts |
Posted - 2005-08-22 : 18:23:19
|
| Because you are populating an HTML SELECT control, I would suggest that you use a Stored Procedure rather than issuing a direct SELECT against a View. Your Stored Procedure could then include the ORDER BY for you. It could also do a DISTINCT on the results of the above SELECT statement to get rid of the duplicate (None) entries. In fact, a DISTINCT is probably a better route than your GROUP BY.Or, you might consider making the addition of a None entry as part of the web code and not the SQL code, and in your SQL inlude a WHERE T.CODE IS NOT NULL clause.---------------------------EmeraldCityDomains.com |
 |
|
|
|
|
|