strange behavior of <> to filter null values

Posted by Kerezo on Stack Overflow See other posts from Stack Overflow or by Kerezo
Published on 2012-04-07T05:27:34Z Indexed on 2012/04/07 5:28 UTC
Read the original article Hit count: 110

Filed under:
|
|

Hi experts: I have a table Called tblAlarm and it has some records like this:

enter image description here

I have another table for determine what user see what message:

enter image description here

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 :

enter image description here

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

© Stack Overflow or respective owner

Related posts about sql

Related posts about sql-server