Solved

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

Posted on 2014-09-12
3
86 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:Scott Pletcher
Scott Pletcher 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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Suggested Solutions

Long way back, we had to take help from third party tools in order to encrypt and decrypt data.  Gradually Microsoft understood the need for this feature and started to implement it by building functionality into SQL Server. Finally, with SQL 2008, …
If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

776 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