Solved

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

Posted on 2014-09-12
3
87 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

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

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…
How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

756 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