34
I’m having second thoughts about using the ISNULL
and COALESCE
.
Currently creating a query in SQL Server, I was left with doubt about ISNULL
and COALESCE
,
I did some research and I was able to find out the difference between them. Only I came up with some
doubts I couldn’t find.
I realized the following query:
Doubts:
When reading on some websites I saw that the ISNULL
OR COALESCE
there is some difference in the time of select
on bench
only I couldn’t figure out which one, because the two have the same behavior when performing the following query?
SELECT 'A' + ISNULL(NULLIF('abc', 'abc'), ' ') + 'A' AS Using_ISNULL,
Resultado: A A
SELECT 'A' + COALESCE(NULLIF('abc', 'abc'), ' ') + 'A' AS Using_ISNULL
Resultado: A A
Only on some websites they said ISNULL
or COALESCE
when string would look like this
Ex: If Column Has Size VARCHAR(50)
SELECT 'A' + COALESCE OU ISNULL(NULLIF('abc', 'abc'), ' ') + 'A' AS Using_ISNULL
Resultado: A(ESPAÇO 48 "")A
that’s what I could understand, no other site showed examples for better understanding, I wanted to know the difference between the two in the bank question?
It got a little difficult to describe my doubt.
I don’t know if you saw it, but yesterday I supplemented my answer, and now I just gave her another one. Initially I had not noticed the discrepancy in the results you showed, but now I believe the answer clarifies your doubt.
– bfavaretto