Click here to Skip to main content
14,545,828 members
Rate this:
Please Sign up or sign in to vote.
See more:
rewrite below incorrect statement in two ways using isnull and coalesce
select * from Test_Table where Test_ID=null


What I have tried:

rewrite below incorrect statement in two ways using isnull and coalesce
select * from Test_Table where Test_ID=null
Posted
Updated 7-Jul-18 5:09am
Rate this:
Please Sign up or sign in to vote.

Solution 1

SELECT    TOP 10 *
FROM      Google
WHERE    (NULL, Coalesce) IN SearchTerms
   
Rate this:
Please Sign up or sign in to vote.

Solution 2

Not clear what your question is. But here an example on how to use COALESCE and ISNULL function.

--if first column/Test_ID is null, use value from second column which is ''
SELECT    *
FROM      Test_Table 
WHERE    COALESCE(Test_ID, '') = ''

--if Test_ID is null, return ''
SELECT    *
FROM      Test_Table 
WHERE    ISNULL(Test_ID,'') = ''

Here you can find out more about the mentioned functions.
COALESCE (Transact-SQL) | Microsoft Docs[^]
Deciding between COALESCE and ISNULL in SQL Server[^]
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100