Glowworm27
Programmer
Found this usefull
George Oakes
Check out this awsome .Net Resource!
Code:
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
/************************************** Proper Case Function *************************************************
* This function will accept a Varchar up to 2000 chars long (or modify the input definition to suit your needs)
* And return a Varchar up to 2000 chars long, that has been converted to proper case. The Function assumes that a
* Single space, a comma, or a dash (-) delimit new words, and will capitalize the the first letter in each word.
*
* Inputs : up to 2000 Varchar characters
* Returns: up to 2000 Varchar Characters properly cased ( first letter of each word is Upper Case the rest are lower case
* Usage: Select dbo.ProperCase('THIS is A ReaLY bAD EXamPLE OF IMprOPER CASE')
* Returned: This Is A Realy Bad Example Of Improper Case
*/
ALTER FUNCTION dbo.ProperCase
(
--The string to be converted to proper case
@input VARCHAR(2000)
--The character(s) to be recognized as separating strings to be capitalized
)
RETURNS VARCHAR(2000)
AS
BEGIN
DECLARE @byte SMALLINT
DECLARE @delimFound BIT
DECLARE @delims VARCHAR(10)
SET @byte = 1
SET @delimFound = 1
SET @delims = ' ,-'
WHILE @byte <= LEN(@input)
BEGIN
IF CHARINDEX(SUBSTRING(@input, @byte, 1), @delims) > 0
SET @delimFound = 1
ELSE
BEGIN
IF @delimFound = 1
BEGIN
SET @input = STUFF(@input, @byte, 1, UPPER(SUBSTRING(@input, @byte, 1)))
SET @delimFound = 0
END --IF
ELSE
SET @input = STUFF(@input, @byte, 1, LOWER(SUBSTRING(@input, @byte, 1)))
END --ELSE
SET @byte = @byte + 1
END --WHILE
RETURN @input
END --FUNCTION
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
George Oakes
Check out this awsome .Net Resource!