Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 correct/detect improper case

Author  Topic 

petebob796
Starting Member

35 Posts

Posted - 2008-05-22 : 05:15:59
I have been through our database and we have a culprit who has been inputting all names in full capitals which I have always found particularly annoying. I want to convert them all to proper case for which I found the code below. However how can I detect the set where they have inproper case.

CREATE FUNCTION dbo.pCase 
(
@strIn VARCHAR(255)
)
RETURNS VARCHAR(255)
AS
BEGIN
IF @strIn IS NULL
RETURN NULL

DECLARE
@strOut VARCHAR(255),
@i INT,
@Up BIT,
@c VARCHAR(2)

SELECT
@strOut = '',
@i = 0,
@Up = 1

WHILE @i <= DATALENGTH(@strIn)
BEGIN
SET @c = SUBSTRING(@strIn,@i,1)
IF @c IN (' ','-','''')
BEGIN
SET @strOut = @strOut + @c
SET @Up = 1
END
ELSE
BEGIN
IF @up = 1
SET @c = UPPER(@c)
ELSE
SET @c = LOWER(@c)

SET @strOut = @strOut + @c
SET @Up = 0
END
SET @i = @i + 1
END
RETURN @strOut
END
GO

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2008-05-22 : 05:19:03
Why do you need that? This function will work on all data whether in proper case or not.

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-05-22 : 05:53:16
quote:
Originally posted by harsh_athalye

Why do you need that? This function will work on all data whether in proper case or not.

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"


may be coding standards
Go to Top of Page

petebob796
Starting Member

35 Posts

Posted - 2008-05-22 : 06:54:19
I have sorted it now I processed the table through the UDF and compared the input to the output to see which it would affect.

The reason I wanted to detect the ones with inproper case was to check how many there were and confirm it's all nice and working as I would be running it on a database with 90,000 biographical records.
Go to Top of Page
   

- Advertisement -