I'm not sure how to use ISNULL
and COALESCE
.
Currently when I create a query in SQL Server, I have doubts about ISNULL
and COALESCE
,
I did some research and I was able to discover the difference of both. Only that I came up with some
doubts that I could not find.
I made the following query :
Questions: WhenIreadonsomesites,IsawthatISNULL
ORCOALESCE
hasanydifferenceinthetimeofselect
inbank butIcouldnotfigureoutwhichone,becausethetwohavethesamebehaviorwhenperformingthefollowingquery?
SELECT'A'+ISNULL(NULLIF('abc','abc'),'')+'A'ASUsing_ISNULL,Resultado:AASELECT'A'+COALESCE(NULLIF('abc','abc'),'')+'A'ASUsing_ISNULLResultado:AA
OnlysomesitessaidISNULL
orCOALESCE
whenstringwouldlooklikethisEx:IfthecolumnhasthesizeVARCHAR(50)
SELECT'A'+COALESCEOUISNULL(NULLIF('abc','abc'),'')+'A'ASUsing_ISNULLResultado:A(ESPAÇO48"")A
This was what I could understand, but no site showed examples for better understanding, I wanted to know What is the difference of both in the question in bank?
It was a bit difficult to describe my doubt.