I have a procedure to search the database. My problem is it gives timeout error sometimes. I think I need to speed it up but I don't know a better way to do it than I done it here. I thought I better ask you, I'd be very glad if you could share your opinions with me.Here's the procedure:create procedure Search_Word@word varchar(100),@fieldToSearch varchar(20)='ALL',@dateinterval varchar(20)='ALL',@forumToSearch varchar(1000),@date varchar(100)asset nocount ondeclare @sql nvarchar(3000)declare @field varchar(3000)declare @date2 varchar(3000)declare @forum varchar(3000)set @forum=' and K.K_Forum in'+@forumToSearchif @fieldToSearch='ALL' begin set @field=' ((M.M_Message like '''+@word+''') or (K.K_Topic like '''+@word+''') or (K.K_Message like '''+@word+''')) ' endif @fieldToSearch='topics' begin set @field=' (K.K_Topic like '''+@word+''') ' endif @fieldToSearch='messages' begin set @field=' ((M.M_Message like '''+@word+''') or (K.K_Message like '''+@word+''')) ' endif @dateinterval='ALL' begin set @date2='' endelse begin set @date2=' and (K.K_Date>'''+@date+''' or M.M_Date>'''+@date+''') ' endset @sql='declare @tmpTable table (K_ID int,K_Topic varchar(200),K_Poster varchar(200),K_Date varchar(50), K_ReplyCount smallint,K_LastPoster varchar(200),K_LastReplyDate varchar(50), K_LastReplyTime varchar(50))insert into @tmpTableselect top 200 K.K_ID, K.K_Topic, (select U_Nickname from dbo.[MEMBERS] where U_ID=K.K_Poster) as K_LastPoster, K.K_Date, K.K_ReplyCount, (select U_Nickname from dbo.[MEMBERS] where U_ID=K.K_LastPoster) as K_LastPoster, K.K_LastReplyDate,K.K_LastReplyTimefrom dbo.[TOPICS] as K left outer join dbo.[MESSAGES] as M on K.K_ID = M.M_KonuIDwhere '+@field+' '+@date2+' '+@forum+' and (K.K_Statu=''1'')order by K.K_LastReplyDate,K.K_LastReplyTime,K.K_Dateselect distinct K_ID,K_Topic,K_Poster,K_Date,K_ReplyCount,K_LastPoster,K_LastReplyDate,K_LastReplyTimefrom @tmpTableorder by K_LastReplyDate,K_LastReplyTime,K_Date desc'exec dbo.sp_executesql @sqlgo