MS SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesMS SQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
  #1  
Old September 11th, 2003, 08:36 PM
jake_junk jake_junk is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 1 jake_junk User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
User defined functions for proper case

I am trying to write a function that takes as its input, a proper name and returns the name in proper case. For example, I type in JON DOE and it returns Jon Doe, or jon doe and returns Jon Doe. Any help would be greatly appreciated.

Reply With Quote
  #2  
Old September 12th, 2003, 12:47 AM
SQLMan SQLMan is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Location: KC
Posts: 6 SQLMan User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Try a google.com search using "sql proper name". The first site found is "SQL Server Examples" by Greg Larson. See http://www.geocities.com/sqlserverexamples/string6.htm

Reply With Quote
  #3  
Old September 12th, 2003, 12:48 AM
SQLMan SQLMan is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Location: KC
Posts: 6 SQLMan User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
This scriipt can be changed to a function:

create table #temp (
name varchar(100))
insert into #temp values('GREGORY ALAN LARSEN')
insert into #temp values('TODD JOSHUA SMITH')
select
-- Get First Character of First Name
upper(substring(name,1,1)) +
-- Get rest of first name
lower(substring(name,2,charindex(' ',name)-2)) + ' ' +
-- Get first Character of Middle Name
upper(substring(name,charindex(' ',name)+1,1)) +
-- Get rest of Middle Name
lower(substring(substring(name,charindex(' ',name)+2,len(name)),1,
charindex(' ',substring(name,charindex(' ',name)+2,len(name)))-1)) + ' ' +
-- Get First Character to Last Name
upper(substring(substring(name,charindex(' ',name)+2,len(name)),
charindex(' ',substring(name,charindex(' ',name)+2,len(name)))+1,1)) +
-- Get Rest of Last Name
lower(substring(substring(name,charindex(' ',name)+2,len(name)),
charindex(' ',substring(name,charindex(' ',name)+2,len(name)))+2,
len(substring(name,charindex(' ',name)+2,len(name)))))
from #temp
drop table #temp

Reply With Quote
  #4  
Old September 12th, 2003, 12:50 AM
SQLMan SQLMan is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Location: KC
Posts: 6 SQLMan User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Greg Larson's comments:
"This script will proper case the first, middle, and last name for a person. This script strips apart the first, middle and last name then uppercase the first character of each name, and lowercases the rest. This script only works if there is a single space between each names. This script uses the charindex function to identify the character offset of the space between each name. If multiple spaces exist they will need to be removed first (look at "remove white space between multiple words")."

Reply With Quote
  #5  
Old September 12th, 2003, 01:09 AM
SQLMan SQLMan is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Location: KC
Posts: 6 SQLMan User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Greg's routine to remove white space between multiiple words can be changed to locate the first white space and remove remaining white space rather than remove ALL white space.

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesMS SQL Development > User defined functions for proper case


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

 Free IT White Papers!
 
Accelerating Trading Partner Performance
One in five. That's how many partner transactions have at least one error. That is an amazing statistic, particularly given the extraordinary leaps in innovation across the global supply chain during the past two decades. Download this white paper to learn more.

 
Competing on Analytics
This Tech Analysis is designed to help identify characteristics shared by analytics competitors, and includes information about 32 organizations that have made a commitment to quantitative, fact-based analysis.

 
Cost Effective Scaling with Virtualization and Coyote Point Systems
An overview of the industry trend toward virtualization, how server consolidation has increased the importance of application uptime and the steps being taken to integrate load balancing technology with virtualized servers.

 
Five Checkpoints to Implementing IP Telephony
Implementation planning for IP PBX software and IP telephony has become vital as businesses replace discontinued legacy PBX phone systems. This informative whitepaper outlines five "checkpoints" for any implementation plan that will help make IP communications a successful proposition.

 
Hosted Email Security: Staying Ahead of New Threats
In the last two years, email has become a fierce battleground between the nefarious forces of spam and malware, and the heroes of messaging protection. The spam volumes increased alarmingly every month, bringing clever new forms of phishing and virus propagation attacks.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway