text replacing - finding end of sentence and capitalizing next letter


In a SQL Server text field, I would like to do the following::

If a period '.' is followed by a space ' ' replace the next letter with a capital
esak2000Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Aaron TomoskySD-WAN SimplifiedCommented:
0
sammySeltzerCommented:
0
baretreeCommented:
do you really need to do that on SQL?
string manipulation functions in SQL are so time wasting, not worth handling them there most of the time but if you need to do so, i guess (though both suggestions work) you'd go by the first suggestion in my opinion
when i ask if you really need to do that in SQL i mean, if you're not gonna update tables but just show the result to a client or something, just remember you're gonna execute the function every single time and SQL string manipulation isn't that good for performance...
0
Scott PletcherSenior DBACommented:
Naturally change the varchar(8000) to whatever length you need.
CREATE FUNCTION dbo.CapitalizeAfterPeriodSpace (
    @string varchar(8000)
    )
RETURNS varchar(8000)
AS
BEGIN
DECLARE @byte int
SET @byte = CHARINDEX('. ', @string, 1)
WHILE @byte > 0
BEGIN
    SET @string = STUFF(@string, @byte + 2, 1, UPPER(SUBSTRING(@string, @byte + 2, 1)))
    SET @byte = @byte + 2
    SET @byte = CHARINDEX('. ', @string, @byte)
END --WHILE
RETURN @string
END --FUNCTION

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server 2005

From novice to tech pro — start learning today.