Quick Search for:  in language:    
little,snippet,will,allow,change,words,upperc
   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:
 
Login





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



 
 
   

Uppercase

Print
Email
 
VB icon
Submitted on: 10/26/2003 1:35:37 PM
By: Peter Schmitz 
Level: Advanced
User Rating: Unrated
Compatibility:SQL Server 2000

Users have accessed this code 1377 times.
 
(About the author)
 
     This little snippet will allow you to change words in characterfields to uppercase. Might be usefull on Fullname fields or similar datafields.
 
code:
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: Uppercase
-- Description:This little snippet will 
--     allow you to change words in characterfi
--     elds to uppercase. Might be usefull on F
--     ullname fields or similar datafields.
-- By: Peter Schmitz
--
-- Assumes:The code will query for all f
--     ields containing a space. Then, it will 
--     query those rows, find where the space i
--     s, and convert the next character to upp
--     ercase. This was tested on a SQL Server 
--     2000 system. Might work on other version
--     s too.
--
-- Side Effects:None known.
--
--This code is copyrighted and has-- limited warranties.Please see http://
--     www.Planet-Source-Code.com/vb/scripts/Sh
--     owCode.asp?txtCodeId=777&lngWId;=5--for details.--**************************************
--     

DECLARE @Name varchar(60)
DECLARE curName CURSOR FOR 
SELECT FullName FROM Customers WHERE FullName LIKE '% %'
OPEN curName
FETCH NEXT FROM curName INTO @Name
WHILE @@FETCH_STATUS = 0
    BEGIN 
    	DECLARE @SpacePosition int
    	-- Find out WHERE first space IS
    	SELECT @SpacePosition = CHARINDEX (' ', @Name)
    	-- Make Character after first space uppercase
    	SELECT @Name = LEFT(@Name, (@Spaceposition)) + UPPER(SUBSTRING(@Name, (@Spaceposition + 1), 1)) + RIGHT(@Name, (Len(@Name) - (@Spaceposition + 1)))
    	-- Optional part IN CASE there's more than one space
    	-- Just uncomment. Copy/paste the lines FOR ANY additional
    	-- spaces
    	--	SELECT @SpacePosition = CHARINDEX (' ', @Name, @SpacePosition + 1)
    	--	SELECT @Name = LEFT(@Name, (@Spaceposition)) + UPPER(SUBSTRING(@Name, (@Spaceposition + 1), 1)) + RIGHT(@Name, (Len(@Name) - (@Spaceposition + 1)))
    	-- UPDATE TABLE
    	UPDATE Customers
    		SET FullName = @Name WHERE CURRENT OF curName
    	FETCH NEXT FROM curName INTO @Name
END

CLOSE curName DEALLOCATE curName


Other 4 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.).
Reason:
 
Your Vote!

What do you think of this code(in the Advanced 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
10/27/2003 10:29:35 AM:Markus Q
Why not just do:
UPDATE a
SET 
a.FullName = UPPER(a.FullName)
FROM 
Customers a
WHERE a.FullName is not 
null
It's faster and doesn't require 
a cursor.
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
10/27/2003 10:30:34 AM:Markus Q
Nevermind my last comment.  You're 
really performing a titlecase.
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
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.
 
Name:
Comment:

 

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.