Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2014-09-12
3
Medium Priority
?
97 Views
Last Modified: 2014-09-17
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
Comment
Question by:BlakeMcKenna
3 Comments
 
LVL 41

Accepted Solution

by:
Kyle Abrahams earned 1000 total points
ID: 40319701
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
 
LVL 70

Assisted Solution

by:Scott Pletcher
Scott Pletcher earned 1000 total points
ID: 40323461
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
 

Author Closing Comment

by:BlakeMcKenna
ID: 40328659
Sorry for the delay...both solutions worked!

Thanks guys!
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
Integration Management Part 2
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

926 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question