Home
  Home
Home
Search
Articles
Page Tag-Cloud
  Software
Software Tag-Cloud
Submit Patch
Building from Source
Open Source Definition
  Popular Tags
C Plus Plus
Source Code
Legacy
Class
Console
  Members
Login
Web-Email
Notable Members
  Official
Our Company
Copyright Information
Software EULA
GPL EULA
LGPL Eula
Pre-Release EULA
Privacy Policy
  Support
Make Contact
 
 
Proper Name Casing in SQL Server

Need to format a name for a form or cleanse some proper nouns in your data? Well, this isn't perfect by any means because it doesn't handle mixed cased names such as "McMinn", but it's a pretty good start!

CREATE FUNCTION ProperCase(@string VarChar(8000)) RETURNS VarChar(8000) AS
BEGIN--FUNCTION
	SET @string = lower(@string)

	DECLARE @i INT
	SET @i = ASCII('a')

	WHILE @i <= ASCII('z')
	BEGIN--WHILE
		SET @string = Replace( @string, ' ' + char(@i), ' ' + char(@i-32))
		SET @i = @i + 1
	END--WHILE

	SET @string = char(ASCII(left(@string, 1))-32) + right(@string, len(@string)-1)

	RETURN @string
END--FUNCTION


Is this code snippet, product or advice warrantied against ill-effect and/or technical malaise? No. No it's not! Not expressed - Not implied - not at all.



Tags:
 Function    Snippet    SQL Server  

Created by Josh Patterson on 2/8/2013, last modified by Josh Patterson on 2/8/2013

No comments currently exists for this page. Why don't you add one?
First Previous Next Last 

Login or signup to leave a comment.
 
Copyright © 2017 NetworkDLS.
All rights reserved.
 
Privacy Policy | Our Company | Contact