CREATE PROCEDURE [dbo].[spUpdateUserOnline] 
	@username	varchar(50)
AS
BEGIN
	IF (SELECT COUNT(*) FROM [tblChatUsersOnline] WHERE [username]=@username) > 0 
		BEGIN
			UPDATE [tblChatUsersOnline] SET [timestamp]=getdate() WHERE [username]=@username;
		END
	ELSE
		BEGIN
			INSERT INTO [tblChatUsersOnline] ([username]) VALUES (@username);
		END
	DELETE FROM [tblChatUsersOnline] WHERE timestamp < DATEADD( mi, -10, getDate());
END