[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 101
  • Last Modified:

Need help with a SQL Query (add 'All' option).

I have a SQL Query that loads an "ID" column and a "Name" column into a datatable that will be assigned to a ComboBox. The ValueMember will contain the "ID" and the DisplayMember will contain the "Name". However, the first row in the datatable needs to be the word "All", even though it doesn't reside in any DB Table. Is this possible.

I basically need the first entry in the ComboBox to be "All"...
0
BlakeMcKenna
Asked:
BlakeMcKenna
2 Solutions
 
Kyle AbrahamsSenior .Net DeveloperCommented:
What I normally do in the case like that is insert it after the fact (on the .Net side).

If you need / want it from the sql query:

select -1 id , cast ('All' as varchar(100)) as Name
union all
select id, name from table
0
 
Scott PletcherSenior DBACommented:
The ValueMember will contain the "ID" and the DisplayMember will contain the "Name".

SELECT 0 AS ValueMember, 'All' AS DisplayMember
UNION ALL
SELECT ID, ... --where ID > 0
FROM ...
ORDER BY ValueMember
0
 
BlakeMcKennaAuthor Commented:
Sorry for the delay...both solutions worked!

Thanks guys!
0

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now