I've been trying for awhile by changing my query around but no LUCK! I have tables:
Demographic
( name, gender, nationality, ethnicity etc)
Reference
(ID, Code as varchar, Description varchar)
Basically I add all my values in the reference table like nationality, Gender, ethnicity then I link it to demographics, eg. ID:1 , Code: Gender , Description: Male
So in demographics any male will have value 1 ( the Reference.ID)
I've written this query:
Select Id, fname, Surname
,e.Description as Nationality
,a.Description as Gender
FROM Demographics d, Reference e, Reference a
WHERE (d.Nationality = e.ID OR d.Nationality IS NULL) AND (d.Gender = a.ID OR
d.Gender IS NULL)
Without the IS NULL parts it works but it excludes all NULL values. But when I add IS NULL it returns inaccurate values like in Gender column I will have ethnicity values.
Any help will be appreciated.
NULL, in SQL Server, is treated as an unknown value. Thus, an expression like[Column] != 1will return false, if the value of[Column]isNULL. Also, it's worth noting thatNULL = NULLwould also return false; as an unknown does not equal an unknown in SQL Server. The only way to compare to aNULLis by usingIS NULLandIS NOT NULL. Without any sample or expected data, however, I have no idea what you are expecting here. Forum Etiquette: How to post a T-SQL Question.WHEREclause.JOINsyntax has been around for decades. Use it.