I am trying to give a score on my query results. Each 'categories' array might contain many category integers, or it might be null. If it's null then it should be considered as found.
In the query below I'm searching for category 3 which is found. However I don't know how I can check if the Array categories is NULL so I can return 1 as well which will solve my problem.
I have tried:
WHERE Value IN(3) OR Value IS NULL)
WHERE Value IN(3) OR Value.length =0)
WHERE Value IN(3) OR Value = '')
etc....
For example
{"categories":[1,2,3],"distance":[130,300],"companysize":[2,4],"budget":[5000,1000000]}{"categories":[],"distance":[60,200],"companysize":[1,2],"budget":[250,100]}
SQL
SELECT * FROM (SELECT
(CASE WHEN EXISTS (Select * FROM OPENJSON(Preference,'$.categories')
WHERE Value IN(3) OR Value IS NULL) -- < problem is here
THEN 1 ELSE 0 END)
matchscore, p.*
FROM FinNotificationsPreferences p) x