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?

[Webinar] Streamline your web hosting managementRegister Today

x
 
TulkinOlegConnect With a Mentor Commented:
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
 
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
All Courses

From novice to tech pro — start learning today.