PDA

View Full Version : returning multiple records with charindex


ghell
07-29-2005, 11:58 AM
i am trying to search a string for another string (actually its all binary but that doesnt make any diff) and then return 1 record for every occurance it finds

im guessing the way to do this is loop through using charindexes to start where the last 1 was found but i cant work out how to do this in a stored procedure (as some of you may have guessed by now im pants at this ;) )

for example every time 0x0F34 is found in field a, i it should return a record with fields b and c in it (i dont need to know where it was found i just need 1 record for every occurance even though they will all contain the same data)

at the moment i am usingSELECT b, c FROM t WHERE (CharIndex( Cast(422548 As Binary(4)) , a) % 10 = 4)which works great but it only returns a record for the first instance found.

KTTHOOL
03-14-2009, 03:30 PM
I understood that all you want to is to fetch data.
In sql 2005 it would be like this

create procedure Find
@search varchar(50)
AS
SELECT b, c FROM t WHERE (CharIndex( Cast(@search As Binary(4)) , a) % 10 = 4)
that should do it dude

ghell
03-14-2009, 03:31 PM
Please do not dig up threads from 2005.