Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

To MeanGreen

Status
Not open for further replies.

tpasters

Programmer
Joined
Jul 19, 2001
Messages
8
Location
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
 
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!)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top