2

This is my code:

DECLARE @TABLE TABLE
(
    RecordID BIGINT,
    RecordValue NVARCHAR(10)
)

INSERT INTO @TABLE(RecordID,RecordValue)
VALUES  (1,'100')
       ,(2,NULL)
       ,(3,'200')
       ,(4,NULL)
       ,(5,'200')

SELECT RecordID,RecordValue
FROM @TABLE
WHERE RecordValue NOT IN ('200') 

OUTPUT:

1 100

Desire OUTPUT:

1 100

2 NULL

4 NULL

How can I get the 'NULL' values too?

Actually, my the sql statement is generated by a lot of procedures and functions, I am limited in doing operations like using ISNULL function. The final statement is in the following format:

WHERE RecordValue NOT IN ('CSV...') 
WHERE RecordValue IN ('CSV...') 
or combinatnation from both 
RecordValue NOT IN ('CSV...') AND RecordValue IN ('CSV...') 

Is there a way to get NULL values too in this way?

2 Answers 2

4

Try this:

SELECT RecordID,RecordValue 
FROM @TABLE 
WHERE RecordValue NOT IN ('200') OR RecordValue IS NULL

When value is NULL then comparison with it is always NULL so you have to take it into account.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks. I managed to change the procedures in order to generated this code.
1

Like this:

SELECT RecordID,RecordValue
FROM @TABLE
WHERE ISNULL(RecordValue,'') NOT IN ('200') 

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.