Greetings all,

I have this udf that I'm trying to create. I'm following an example of using while from the manual. However I receive a syntax error. I'm using ASA Anyhwere 7.0. Any help would be greatly be appreciated.


/* Syntax*/


CREATE FUNCTION sf_last_charindex(@delim varchar(30),
@in_string varchar(512))
RETURNS integer

BEGIN

DECLARE @posFound integer;
DECLARE @posStart integer;

SET @posFound = 0;
SELECT DATALENGTH(@in_string)
INTO @posStart ;

/* Get the position of last occurence of a specified delimiter. */
WHILE @posFound = 0 AND @posStart > 0
BEGIN
SELECT CHARINDEX(@delim, @in_string)
INTO @posFound;

IF posFound = 0
SET posStart = posStart - 1
ELSE
BREAK


END;

/* Return the position of the last occurence. */
RETURN (@posFound);
END;