Quick Search for:  in language:    
   Code/Articles  |  Newest/Best  |  Community  |  Jobs  |  Other  |  Goto  | 
CategoriesSearch Newest CodeCoding ContestCode of the DayAsk A ProJobsUpload
SQL Stats

 Code: 44,501. lines
 Jobs: 119. postings

 How to support the site

Sponsored by:

You are in:

Latest Code Ticker for SQL.
Create thousand Data Base users quickly
By N.D.I.Samantha on 1/1

Numbers from String
By Jeff Michelson on 12/30

Number to words in a single query
By Joseph Varghese on 12/24

Click here to see a screenshot of this code!The Best Columns to Index
By Sherenato on 12/23

(Screen Shot)

Click here to put this ticker on your site!

Add this ticker to your desktop!

Daily Code Email
To join the 'Code of the Day' Mailing List click here!

Affiliate Sites


Proper Case All Words - UDF

VB icon
Submitted on: 11/3/2003 9:40:57 AM
By: Tim Cook (Intellisoft)  
Level: Intermediate
User Rating: Unrated
Compatibility:SQL Server 2000, SQL Server 7.0

Users have accessed this code 1137 times.
     Proper Case All words in a string of words, and removes any extra spaces. A UDF in SQL 2000 but can be changed to a Stored Procedure in other SQL versions. This was resubmitted. I tried to edit my previous submission and the site deleted it. A user pointed out that if a 1 charater string was sumitted the next word would not be capitalized. This submission fixes that problem.
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
Terms of Agreement:   
By using this code, you agree to the following terms...   
1) You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.   
2) You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
3) You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
4) You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.

-- Name: Proper Case All Words - UDF
-- Description:Proper Case All words in 
--     a string of words, and removes any extra
--      spaces. A UDF in SQL 2000 but can be ch
--     anged to a Stored Procedure in other SQL
--      versions.
This was resubmitted. I tried TO edit my previous submission AND the site deleted it.
A USER pointed out that IF a 1 charater string was sumitted the next word would NOT be capitalized. This submission fixes that problem.
-- By: Tim Cook (Intellisoft)
-- Inputs:String you want to Proper Case
--     . example: "THIS entry NEEDSto beProperC
--     ASE"
-- Returns:String formatted to Proper Ca
--     se. example: "This Entry Needs To Be Pro
--     per Case"
--This code is copyrighted and has-- limited warranties.Please see http://
--     www.Planet-Source-Code.com/vb/scripts/Sh
--     owCode.asp?txtCodeId=780&lngWId;=5--for details.--**************************************

--The string to be converted to proper c
--     ase
@input varchar(50)
--This function returns the proper case 
--     string of varchar type
RETURNS varchar(50)
    	IF @input IS NULL 
    		--Just RETURN NULL IF input string IS NULL
    	DECLARE @output varchar(50)
    	--Integer variable declarations
    	DECLARE @ctr int, @len int, @NewWord int, @White int
    	--Constant declarations
    	--Variable/Constant initializations
    	SET @ctr = 1
    	SET @NewWord = 1
    	SET @len = LEN(@Input)
    	SET @output = ''
    	SET @LOWER_CASE_a = 97
    	SET @LOWER_CASE_z = 122
    	SET @WHITE_SPACE = ' '
    WHILE @ctr <= @len
        	--This loop will Remove reccuring white spaces
        SET @White = 1
        	WHILE SUBSTRING(@input,@ctr,1) = @WHITE_SPACE
             IF @White = 1
             		 SET @output = @output + SUBSTRING(@input,@ctr,1)
             		 SET @ctr = @ctr + 1
            	 SET @White = @White + 1
                SET @output = @output + SUBSTRING(@input,@ctr,0)
                 		SET @ctr = @ctr + 1

END IF @NewWord = 1 BEGIN --Converting the first character TO upper CASE SET @output = @output + UPPER(SUBSTRING(@input,@ctr,1)) SET @ctr = @ctr + 1 IF SUBSTRING(@input,@ctr,1) = @WHITE_SPACE BEGIN -- Added FOR 1 Char word SET @NewWord = 1 END ELSE BEGIN SET @NewWord = 0 END END ELSE BEGIN WHILE SUBSTRING(@input,@ctr,1) != @WHITE_SPACE IF ASCII(SUBSTRING(@input,@ctr,1)) BETWEEN @LOWER_CASE_a AND @LOWER_CASE_z BEGIN SET @output = @output + LOWER(SUBSTRING(@input,@ctr,1)) SET @ctr = @ctr + 1 END ELSE BEGIN SET @output = @output + LOWER(SUBSTRING(@input,@ctr,1)) SET @ctr = @ctr + 1 END SET @NewWord = 1 END END

Other 1 submission(s) by this author


Report Bad Submission
Use this form to notify us if this entry should be deleted (i.e contains no code, is a virus, etc.).
Your Vote!

What do you think of this code(in the Intermediate category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor See Voting Log
Other User Comments
11/12/2003 11:05:08 AM:
It is better to have an easy access or 
download link for this items.
Keep the Planet clean! If this comment was disrespectful, please report it:

Add Your Feedback!
Note:Not only will your feedback be posted, but an email will be sent to the code's author in your name.

NOTICE: The author of this code has been kind enough to share it with you.  If you have a criticism, please state it politely or it will be deleted.

For feedback not related to this particular code, please click here.


Categories | Articles and Tutorials | Advanced Search | Recommended Reading | Upload | Newest Code | Code of the Month | Code of the Day | All Time Hall of Fame | Coding Contest | Search for a job | Post a Job | Ask a Pro Discussion Forum | Live Chat | Feedback | Customize | SQL Home | Site Home | Other Sites | About the Site | Feedback | Link to the Site | Awards | Advertising | Privacy

Copyright 1997 by Exhedra Solutions, Inc. All Rights Reserved.  By using this site you agree to its Terms and Conditions.  Planet Source Code (tm) and the phrase "Dream It. Code It" (tm) are trademarks of Exhedra Solutions, Inc.