Solved

SQL Server populating a drop-down result set with Null

Posted on 2014-09-18
5
115 Views
Last Modified: 2014-10-05
I have a drop down populated with a values from a table lets call SalesContacts.  Currently if someone selects any one of these contacts I take the selected value, set it to variable and essentially do a lookup/filter to display only the data of the selection.

My problem is if someone wants to clear the data they can not clear the data since I have no value called Null in the set of values.  How do I populate an additional value called Null for the universe of values ?
0
Comment
Question by:upobDaPlaya
  • 3
5 Comments
 
LVL 26

Assisted Solution

by:Shaun Kline
Shaun Kline earned 250 total points
ID: 40331118
You could insert a new entry at the top of your list with a value (let's say -1) and text (maybe "(All)"). When this item is selected, your code / query would handle this specific value to "remove" the existing filter from the your query.
0
 
LVL 65

Accepted Solution

by:
Jim Horn earned 250 total points
ID: 40331121
Give something like this a whirl, then when yu display it on your report only show the id and name columns:

SELECT NULL as id, '< ALL >' as name, 1 as sort_order
UNION ALL
SELECT id, name, 2 as sort_order
FROM SalesContacts
ORDER BY name, sort_order
0
 

Author Comment

by:upobDaPlaya
ID: 40331548
Hi Jim,

It says invalid column name 'ID' ?  Is this the Unique ID of the table
0
 

Author Comment

by:upobDaPlaya
ID: 40331554
Disregard..I got it..sorry
0
 

Author Closing Comment

by:upobDaPlaya
ID: 40362954
Thanks..for the suggestions
0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

861 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