Replace NULL with string

1

In a datetime field, when the value is NULL should only return - , I tried the IFNULL function

SELECT ISNULL(data, '-') as data FROM tabela

but I get the error

Microsoft OLE DB Provider for SQL Server error '80040e07'

Falha ao converter data e/ou hora da cadeia de caracteres.
    
asked by anonymous 16.05.2016 / 17:18

2 answers

1

Reply created as Requested @Marcelo.

Try:

 SELECT COALESCE(convert(varchar,DATA,103) + ' ' + SUBSTRING(convert(varchar,DATA,114),0,6), '-')
    
19.05.2016 / 16:00
2
select COALESCE( CAST( DATA AS VARCHAR), '-') AS DATA from tabela

or

select ISNULL( CAST( DATA AS VARCHAR ), '-') AS DATA from tabela
    
16.05.2016 / 18:04