Hi. This query only times out when @religion is null... Can anyone help?
DECLARE @Religion varchar(50)
--SET @Religion='L070'
SET @Religion=NULL
select top 1000 u.userID,birthdate,replyrate,lessthan11,photo,DATEDIFF(YEAR, birthdate, GETDATE() ) - CASE WHEN birthdate > GETDATE() THEN 1 ELSE 0 END
AS age from userinfo u,userdetails ud
where ud.userid = u.userID and ud.religion = ( CASE WHEN @Religion IS NULL OR @Religion = '' THEN ud.religion END ) OR CHARINDEX (',' + CAST(ud.religion AS varchar) + ',', ',' + @Religion + ',' ) > 0
Thanks
Anne