Replace value null

3

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

SELECT   
(SELECT TOP 1 tabela1.data
       FROM tabela1 tabela1
      WHERE tabela1.id = tabela2.id) as data
       FROM tabela2 tabela2
    
asked by anonymous 26.01.2018 / 13:06

3 answers

3

As stated in the other answer, use ISNULL , but this way:

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
    
26.01.2018 / 13:16
3

Only use ISNULL

SELECT ISNULL(tabela1.data,'1900')   

(SELECT TOP 1 tabela1.data
   FROM tabela1 tabela1
  WHERE tabela1.id = tabela2.id) as data
   FROM tabela2 tabela2
    
26.01.2018 / 13:11
2

According to the SQL Server help >, you can use the ISNULL function.

Command Syntax

ISNULL ( check_expression , replacement_value )

So your select would look like this:

SELECT ISNULL(
    (SELECT TOP 1 tabela1.data 
FROM tabela1 tabela1 
WHERE tabela1.id = tabela2.id), '1900') as data 
FROM tabela2 tabela2
    
26.01.2018 / 13:19