Your query could be written differently... however, to find out what's wrong with your query, make the following change and inspect the return values... if EXISTS(SELECT top 1 * FROM tbl_users WHERE sessionID=@sessionID AND DATEDIFF(n,LastUpdate,GETDATE())<=20)begin update tbl_users set LastUpdate = GETDATE() WHERE sessionID=@sessionID Select 0endelse Select sessionID, LastUpdate, DATEDIFF(n,LastUpdate,GETDATE()) from tbl_users WHERE sessionID=@SessionID
An empty result set will tell you you're not matching sessionID, anything else will show you the LastUpdate and DATEDIFF values.