Before I update I want to test whether certain conditions are true but I get the following error.Why?Thanks[error]Server: Msg 170, Level 15, State 1, Line 5Line 5: Incorrect syntax near '>'.Server: Msg 156, Level 15, State 1, Line 20Incorrect syntax near the keyword 'as'.[/error]UPDATE W SET Referrer= CASE Referrer WHEN CHARINDEX('http://', Y.PR) > 0 THEN REPLACE(Y.PR, 'http://', '') WHEN CHARINDEX('http://www.', Y.PR) > 0 THEN REPLACE(Y.PR, 'http://www.', '') ELSE Y.PR END FROM WebLog W INNER JOIN (SELECT IP, (Referrer) as PR FROM WebLog l WHERE [Date] = (SELECT Max([Date]) FROM WebLog WHERE IP=l.IP)) as Y ON W.IP=Y.IP