Using pubs as an example -
Considering the batch below, how would I loop through the 2nd select statement for the number of rows that are selected in the first select statement? Current of course it returns only the last string.
The point of this is to return a short string from each of the rows where the word and is found.
--------- START ---------
declare @i int, @PWORD varchar(30), @PID varchar(10), @PRETURN varchar(50)
set @PWORD='and'
SELECT @PID=title_id, @i=PATINDEX('%and%', notes)
FROM titles where PATINDEX('%and%', notes)>0
select @PRETURN=substring(notes, (@i-25), (@i+24))
from titles where title_id=@PID
print @PWORD
print @PID
print @PRETURN
GO
--------- END ---------
Considering the batch below, how would I loop through the 2nd select statement for the number of rows that are selected in the first select statement? Current of course it returns only the last string.
The point of this is to return a short string from each of the rows where the word and is found.
--------- START ---------
declare @i int, @PWORD varchar(30), @PID varchar(10), @PRETURN varchar(50)
set @PWORD='and'
SELECT @PID=title_id, @i=PATINDEX('%and%', notes)
FROM titles where PATINDEX('%and%', notes)>0
select @PRETURN=substring(notes, (@i-25), (@i+24))
from titles where title_id=@PID
print @PWORD
print @PID
print @PRETURN
GO
--------- END ---------