Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Replace null values with just a blank

Tags:

sql

I currently have a sql statement that outputs data into an excel document. However, every time there is a cell that doesn't have data, it outputs NULL into the cell. I was wondering if there was a way that I could replace NULL with just a blank space? Someone suggested using coalesce to do this, however I haven't ever had the chance to use it so I will have to do some reading on it. Anyone have any other suggestions?

like image 615
David F. Avatar asked Sep 12 '12 18:09

David F.


People also ask

What to replace NULL values with?

Null values are replaced with mean/median.

How do I show blank instead of NULL in tableau?

The steps are simple: Change the data type of the Date to a String (right-click on the field in the list of dimensions and Change Data Type) Right-click on the dimension again (once it's a string) and select Aliases. Set the Alias value for Null to be a space if you want it blank (or a “-“/dash/hyphen/minus/etc)

How can I add zero instead of NULL in SQL?

Use IFNULL or COALESCE() function in order to convert MySQL NULL to 0. Insert some records in the table using insert command.


2 Answers

In your select you can put an IsNull/IfNull round the column. Not particularly efficient but does what you want.

MS SQL

Select IsNull(ColName, '') As ColName From TableName 

MySQL

Select IfNull(ColName, '') As ColName From TableName 
like image 104
Fred Avatar answered Sep 21 '22 13:09

Fred


IFNULL is an Oracle extension (adopted by many other platforms). The "standard" SQL function is coalesce():

SELECT COALESCE(columnName, ' ') AS ColumnName
FROM tableName;
like image 36
wildplasser Avatar answered Sep 19 '22 13:09

wildplasser