Place a hyphen when the value is 0 in select

1

How can I do in% with a mysql (SELECT) so that when the value is equal to query , replace it with 0 .

Value field: int.

    
asked by anonymous 21.02.2017 / 17:50

3 answers

1

@Eduardo Santos,

If you want to change the 0 by the hyphen in a select you do this:

SELECT IF(seu_campo = 0, '-', seu_campo) AS nome_para_esse_resultado FROM sua_tabela;
    
21.02.2017 / 17:53
2

You can use a IF in the query .

The IF receives three "parameters", the first is the condition, the second is the value that the column will assume if the condition is met and the third is the value that the column will assume otherwise. >

Select If(Campo = 0, '-', Campo) From Tabela 

IF Documentation

    
21.02.2017 / 17:54
1
Select IIF(Campo = 0, '-', campo) AS CAMPOSELECIONADO from TABELA

This would work for you.

    
22.02.2017 / 00:56