Avatar of BFanguy
BFanguyFlag for United States of America asked on

SqlServer SQL Statement Where compare two fields from different tables and on is null

Both of these sql statements work fine as long as both tables have values in both fields:
where R.DRAWING_ID <> P.DRAWING_ID

where NOT R.DRAWING_ID = P.DRAWING_ID

But if either one contains a null it does not fire - what do i need to do to get the records where one of the fields is null
Microsoft SQL Server

Avatar of undefined
Last Comment
BFanguy

8/22/2022 - Mon
cyberkiwi

where ((r.drawing_id != p.drawing_id) or (r.drawing_id is null and not p.drawing_Id is null) or (p.drawing_id is null and not r.drawing_id is null))
ASKER
BFanguy

Yea, thats what I just came up with - was kinda hoping there was a different way:

(R.DRAWING_ID <> P.DRAWING_ID OR (R.DRAWING_ID IS NULL AND P.DRAWING_ID IS NOT NULL) OR (R.DRAWING_ID IS NOT NULL AND P.DRAWING_ID IS NULL))

maybe instead of <> or =   - something that would include the nulls
ASKER CERTIFIED SOLUTION
cyberkiwi

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
ASKER
BFanguy

much better, thanks
Your help has saved me hundreds of hours of internet surfing.
fblack61