tags:

views:

1976

answers:

3

I made a view to abstract columns of different tables and pre-filter and pre-sort them. There is one column whose content I don't care about but I need to know whether the content is null or not. So my view should pass an alias as "true" in case the value of this specified column isn't null and "false" in case the value is null.

Is this possible with T-SQL (Microsoft SQL Server 2000)?

Thanks in advance!

A: 

Would this work?

SELECT table.column IS NULL FROM table
brien
Sorry, unfortunately it doesn't work. "IS NULL" can only be used in the WHERE clause.
Anheledir
+11  A: 

You have to use a CASE statement for this:

SELECT CASE WHEN columnName IS NULL THEN 'false' ELSE 'true' END FROM tableName;
Adam Bellaire
Works like a charm, thanks. :)
Anheledir
+2  A: 

for the column in the view you can use something like

CASE WHEN ColumnName is not null THEN 'True' ELSE 'False' END

or in a statement

SELECT s.ID, s.[Name], CASE WHEN s.AchievedDate is not null THEN 'True' ELSE 'False' END [IsAchieved] FROM Schools s

or for further processing afterwards I would personally use

SELECT s.ID, s.[Name], CASE WHEN s.AchievedDate is not null THEN 1 ELSE 0 END [IsAchieved] FROM Schools s

tocs