on ‎2018 Apr 11 11:02 AM
I'm trying to create a function that produces an output of a string in "Proper Case." I have an attempt put together from other works I've found online, but am not having success. I'm not extremely familiar with SQL Anywhere and was hoping someone could lend a hand.
Here's what I have, but it errors at line 5.
CREATE FUNCTION Proper(in @Text long varchar) RETURNS long varchar AS BEGIN declare @Reset bit; declare @Ret long varchar; declare @i int; declare @c char(1); select @Reset = 1, @i=1, @Ret = ''; while (@i <= len(@Text)) select @c= substring(@Text,@i,1), @Ret = @Ret + case when @Reset=1 then UPPER(@c) else LOWER(@c) end, @Reset = case when @c like '[a-zA-Z]' then 0 else 1 end, @i = @i +1 return @Ret; END;
Request clarification before answering.
Try this
CREATE FUNCTION Proper(in @Text long varchar) RETURNS long varchar BEGIN declare @Reset bit; declare @Ret long varchar; declare @i int; declare @c char(1); set @Reset = 1; set @i=1; set @Ret = ''; while (@i <= len(@Text)) loop set @c= substring(@Text,@i,1); set @Ret = @Ret + case when @Reset=1 then UPPER(@c) else LOWER(@c) end; set @Reset = case when @c like '[a-zA-Z]' then 0 else 1 end; set @i = @i +1; end loop; return @Ret; END;
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
That did it, thanks a ton!
| User | Count |
|---|---|
| 15 | |
| 9 | |
| 6 | |
| 5 | |
| 4 | |
| 4 | |
| 3 | |
| 2 | |
| 2 | |
| 2 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.