Happy BirthdayCREATE FUNCTION udf_GetWord ( @str nvarchar(4000) , @Word int , @Delim char(1))RETURNS nvarchar(4000)ASBEGIN DECLARE @LastPosition int, @DelimFound int, @Start int, @End int, @WordFound nvarchar(4000) SELECT @LastPosition = 0, @DelimFound = 0 WHILE (@DelimFound < @Word-1) BEGIN IF (CHARINDEX(@Delim, @str, @LastPosition + 1) = 0) BREAK ELSE BEGIN SET @LastPosition = CHARINDEX(@Delim, @str, @LastPosition + 1) SET @DelimFound = @DelimFound + 1 END END SET @Start = @LastPosition + 1 SET @End = CHARINDEX(@Delim, @str, @LastPosition + 1) - @Start IF (@End = 0) SET @End = LEN(@str) SELECT @WordFound = SUBSTRING(@str,@start,@end) RETURN @WordFoundEND
Brett8-)Hint: Want your questions answered fast? Follow the direction in this linkhttp://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspxAdd yourself!http://www.frappr.com/sqlteam