SQL query returning null values for drop-down list

Right, I have a simple query:

SELECT activityID, ActivityListName
FROM dbo.custom_activity
WHERE dbo.custom_activity.ActivityName IS NOT NULL
ORDER BY ActivityListName ASC

The query is used to populate a drop-down list - activityID is the value returned from list to d/b and ActivityListName is the value displayed in drop-down list.

What I want to do is display an extra option (ie. blank) at the top of the drop-down list so that if no option is selected it returns a NULL value to d/b. At the moment the first entry is selected by default - which means an activityID is always returned to the d/b. This has to be done as part of SQL query as I don't control the drop-down lists.

Is this possible?

Thanks for any help.
asrisbeyAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

knightEknightCommented:
The easiest way to do it is to hard-code the blank option into the dropdown list, but if you really want to do it with SQL then do this:

SELECT 'null' as activityID, '' as ActivityListName

UNION

SELECT activityID, ActivityListName
FROM dbo.custom_activity
WHERE dbo.custom_activity.ActivityName IS NOT NULL
ORDER BY ActivityListName ASC

0
asrisbeyAuthor Commented:
OK, tried this but getting this error message:

Conversion failed when converting the varchar value 'null' to data type int.
0
TulkinOlegCommented:
SELECT null as activityID, '' as ActivityListName

UNION

SELECT activityID, ActivityListName
FROM dbo.custom_activity
WHERE dbo.custom_activity.ActivityName IS NOT NULL
ORDER BY ActivityListName ASC
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.