Solved

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

Posted on 2014-09-12
3
85 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 40

Accepted Solution

by:
Kyle Abrahams earned 250 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 69

Assisted Solution

by:ScottPletcher
ScottPletcher earned 250 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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

Naughty Me. While I was changing the database name from DB1 to DB_PROD1 (yep it's not real database name ^v^), I changed the database name and notified my application fellows that I did it. They turn on the application, and everything is working. A …
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.
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

895 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now