sql – Replace null value

Question:

I would like that when null came in my select to replace it with 1900 , follow select:

SELECT   
(SELECT TOP 1 tabela1.data
       FROM tabela1 tabela1
      WHERE tabela1.id = tabela2.id) as data
       FROM tabela2 tabela2

Answer:

As mentioned in the other answer, use ISNULL , but like this:

SELECT ISNULL(
    (SELECT TOP 1 tabela1.data 
       FROM tabela1 tabela1 
       WHERE tabela1.id = tabela2.id), '1900') as data 
FROM tabela2 tabela2

detail: you can also do this query using join , I think it would be simpler:

SELECT ISNULL(tabela1.data, '1900')
FROM tabela1 
JOIN tabela2 on tabela1.id = tabela2.id
Scroll to Top