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
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
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
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
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