Oct 16, 2002 #1 tpasters Programmer Jul 19, 2001 8 US How would I substitute the '%and%' with a variable like: declare @PWORD varchar(10) set @PWORD='and' select title_id, substring(notes, (PATINDEX('% @PWORD %', notes)-25), (PATINDEX('% @PWORD %', notes)+24)) FROM titles where PATINDEX('% @PWORD %', notes)>0
How would I substitute the '%and%' with a variable like: declare @PWORD varchar(10) set @PWORD='and' select title_id, substring(notes, (PATINDEX('% @PWORD %', notes)-25), (PATINDEX('% @PWORD %', notes)+24)) FROM titles where PATINDEX('% @PWORD %', notes)>0
Oct 16, 2002 #2 MeanGreen IS-IT--Management Sep 12, 2002 672 US Here you go: declare @PWORD varchar(10) declare @sqlstr varchar(1000) set @PWORD='and' select @sqlstr = 'select title_id, substring(notes, (PATINDEX(''%' + @PWORD + '%'', notes)-25), (PATINDEX(''%' + @PWORD +'%'', notes)+24)) FROM titles where PATINDEX(''%' + @PWORD + '%'', notes)>0' exec ( @sqlstr) Hope this helps. (Vote for me if you like the results!) Upvote 0 Downvote
Here you go: declare @PWORD varchar(10) declare @sqlstr varchar(1000) set @PWORD='and' select @sqlstr = 'select title_id, substring(notes, (PATINDEX(''%' + @PWORD + '%'', notes)-25), (PATINDEX(''%' + @PWORD +'%'', notes)+24)) FROM titles where PATINDEX(''%' + @PWORD + '%'', notes)>0' exec ( @sqlstr) Hope this helps. (Vote for me if you like the results!)