Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Replacing "(null)" with blank cell in SQL query result

I believe what I'm asking here is possible, but I haven't find a way yet :

Some cells in the result of my SQL SELECT-FROM-WHERE query are blank, and in DbVisualizer, (null) is written inside. I'd like to display a blank cell instead.
I've already tried with CASE-WHEN and the NVL operator, but it won't let me replace it by a blank '', I'm forced to use some ' ' or 'message'.

I know I could just delete these spaces or messages with Excel later, but I'd like to know if there is a way to do it directly with DbVisualizer, instead of this workaround.


EDIT: Here is what my request looks like :

SELECT *things*,
  CASE WHEN
     (SELECT COUNT(*) FROM table d2 WHERE *join-condition* AND *other condition*) = 1
  THEN
     (*sub-select query*)
  ELSE
     ''
  END
  AS NAME,
  *other things*
  FROM table d1
  WHERE *something*

Thanks a lot !

like image 708
AdrienW Avatar asked Dec 13 '25 23:12

AdrienW


1 Answers

Did you try standard SQL function coalesce(), as below ?

SELECT COALESCE(columnName, '') AS ColumnName FROM tableName;

Syntax:

COALESCE Syntax

COALESCE (expr1, expr2)

is equivalent to:

CASE WHEN expr1 IS NOT NULL THEN expr1 ELSE expr2 END

Similarly,

COALESCE (expr1, expr2, ..., exprn), for n>=3

is equivalent to:

CASE WHEN expr1 IS NOT NULL THEN expr1 
   ELSE COALESCE (expr2, ..., exprn) END

Above examples are from Database SQL Language Reference

like image 71
Shishir Kumar Avatar answered Dec 15 '25 13:12

Shishir Kumar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!