strange behavior of <> to filter null values
- by Kerezo
Hi experts: I have a table Called tblAlarm and it has some records like this:
I have another table for determine what user see what message:
Now I want to write a query to show Messages that user has not seen if message didinot expired.(for example it's year between BeginYear and EndYear and so on ...). I write this query:
SELECT *
FROM
tblAlarms LEFT OUTER JOIN tblUsersAlarms tua ON tblAlarms.Id=tua.MessageID
WHERE @CurrentYear BETWEEN tblAlarms.BeginYear AND tblAlarms.EndYear
AND @CurrentMonth BETWEEN tblAlarms.BeginMonth AND tblAlarms.EndMonth
AND @CurrentDay BETWEEN tblAlarms.BeginDay AND tblAlarms.EndDay
AND (@CurrentHour * 60 + @CurrentMinute) BETWEEN tblAlarms.BeginHour*60 + tblAlarms.BeginMinute AND tblAlarms.EndHour*60 + tblAlarms.EndMinute
--AND (tua.UserID <> 128 AND tua.UserID IS NULL)
and it returns :
but if I unComment last line it does not return any record.How I can determine what messages that users has not been seen?
thanks