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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CHARINDEX infinite loop 1

Status
Not open for further replies.

VBRookie

Programmer
May 29, 2001
331
US
Can anyone tell me why I'm getting an infinite loop on this?

Code:
IF CHARINDEX (',' , @Keywords) > 0 
BEGIN
	WHILE CHARINDEX (',' , @Keywords) > 0 
	BEGIN
-- sql statements here
        END
END

@Keywords is passed in and you can assume that it equals 'boy', 'dog'

Please advise? What have I don't wrong? I'm following the example that I found on google.

Many Thanks,
- VB Rookie
 
Code:
WHILE CHARINDEX (',' , @Keywords) > 0
    BEGIN
       -- sql statements here
      SET @Keywords = SUBSTRING(@Keywords,CHARINDEX (',' , @Keywords)+1,99999)
        END
END

Borislav Borissov
VFP9 SP1, SQL Server 2000/2005.
 

YOU ROCK!!!

That fixed it!

Muchas Gracias :)

- VB Rookie
 
Be careful, you must be sure that your @KeyWord finished with comma, you could miss last keyword if not.

Borislav Borissov
VFP9 SP1, SQL Server 2000/2005.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top