Gostaria de que quando viesse null no meu select substituísse por 1900
, segue select:
SELECT
(SELECT TOP 1 tabela1.data
FROM tabela1 tabela1
WHERE tabela1.id = tabela2.id) as data
FROM tabela2 tabela2
Stack Overflow em Português é um site de perguntas e respostas para programadores profissionais e entusiastas. Leva apenas um minuto para se inscrever.
Inscreva-se para participar desta comunidadeGostaria de que quando viesse null no meu select substituísse por 1900
, segue select:
SELECT
(SELECT TOP 1 tabela1.data
FROM tabela1 tabela1
WHERE tabela1.id = tabela2.id) as data
FROM tabela2 tabela2
Como falado na outra resposta, use o ISNULL, mas desta forma:
SELECT ISNULL(
(SELECT TOP 1 tabela1.data
FROM tabela1 tabela1
WHERE tabela1.id = tabela2.id), '1900') as data
FROM tabela2 tabela2
detalhe: você também pode fazer esta consulta usando join
, acho que ficaria mais simples:
SELECT ISNULL(tabela1.data, '1900')
FROM tabela1
JOIN tabela2 on tabela1.id = tabela2.id
Só usar o ISNULL
SELECT ISNULL(tabela1.data,'1900')
(SELECT TOP 1 tabela1.data
FROM tabela1 tabela1
WHERE tabela1.id = tabela2.id) as data
FROM tabela2 tabela2
Segundo o help on-line do SQL-Server, você pode usar a função ISNULL.
Sintaxe do comando
ISNULL ( check_expression , replacement_value )
Por tanto o seu select ficaria assim:
SELECT ISNULL(
(SELECT TOP 1 tabela1.data
FROM tabela1 tabela1
WHERE tabela1.id = tabela2.id), '1900') as data
FROM tabela2 tabela2