3
I wish that when you came null in my select replaced by 1900
, follows select:
SELECT
(SELECT TOP 1 tabela1.data
FROM tabela1 tabela1
WHERE tabela1.id = tabela2.id) as data
FROM tabela2 tabela2
3
I wish that when you came null in my select replaced by 1900
, follows select:
SELECT
(SELECT TOP 1 tabela1.data
FROM tabela1 tabela1
WHERE tabela1.id = tabela2.id) as data
FROM tabela2 tabela2
3
Only use the ISNULL
SELECT ISNULL(tabela1.data,'1900')
(SELECT TOP 1 tabela1.data
FROM tabela1 tabela1
WHERE tabela1.id = tabela2.id) as data
FROM tabela2 tabela2
Put the answer functionally. For better understanding.
3
As stated in the other answer, use the ISNULL, but in 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 make this query using join
, I think it would be simpler:
SELECT ISNULL(tabela1.data, '1900')
FROM tabela1
JOIN tabela2 on tabela1.id = tabela2.id
2
According to the online help of SQL-Server, you can use the function ISNULL.
Syntax of the command
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
Browser other questions tagged sql sql-server
You are not signed in. Login or sign up in order to post.
The following example locates the average weight of all products. Replaces the value 50 for all NULL entries in the Weight column of the table SELECT AVG(ISNULL(Weight, 50)) FROM Production.Product;
– Rafael Salomão