Returning any of multiple CASE statements in one column

Unless all CASE statements here are True it returns Null for the entire Options column. What I cannot figure out is how to return any True CASE statments, ie: If Col2,Col4 is not null then return only those values. I have no idea what else to try, help?

SELECT 
CASE WHEN Col1 Is Not Null THEN '<li>' + Col1 + '</li>' END +
CASE WHEN Col2 Is Not Null THEN '<li>' + Col2 + '</li>' END +
CASE WHEN Col3 Is Not Null THEN '<li>' + Col3 + '</li>' END +
CASE WHEN Col4 Is Not Null THEN '<li>' + Col4 + '</li>' END Options
FROM TABLE

Again, the issue is unless all Case statements are found, it returns Null for the Options column.

Answers


Like this:

SELECT 
CASE WHEN Col1 Is Not Null THEN '<li>' + Col1 + '</li>' ELSE '' END +
CASE WHEN Col2 Is Not Null THEN '<li>' + Col2 + '</li>' ELSE '' END +
CASE WHEN Col3 Is Not Null THEN '<li>' + Col3 + '</li>' ELSE '' END +
CASE WHEN Col4 Is Not Null THEN '<li>' + Col4 + '</li>' ELSE '' END Options
FROM TABLE

Need Your Help

C# VS2005 Import .CSV File into SQL Database

c# sql-server visual-studio excel

I am trying to import a .csv file into my database. I am able to import an excel worksheet into my database, however due to different file format as .csv as from .xls, I need to make an import func...

How to scroll in a fixed-size ToolStripDropDown

c# winforms toolstripdropdown

I am using a ToolStripDropDown control to implement the dropdown portion of a custom ComboBox-like control. In order to be visually appealing, I am imposing a MaximumSize on the dropdown and manually

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.