Unix Technical Forum

mmsql - transact

This is a discussion on mmsql - transact within the SQL Server forums, part of the Microsoft SQL Server category; --> How change every first character string as Upper Case transact sql ? example ------- tom and jerry jerry and ...


Go Back   Unix Technical Forum > Database Server Software > Microsoft SQL Server > SQL Server

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 03-01-2008, 03:42 PM
info
 
Posts: n/a
Default mmsql - transact

How change every first character string as Upper Case transact sql ?

example
-------
tom and jerry
jerry and tom

result upper
=========
Tom And Jerry
Jerry And Tom



Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 03-01-2008, 03:42 PM
Erland Sommarskog
 
Posts: n/a
Default Re: mmsql - transact

info (informatyk@fitness[CUT]authority.pl) writes:
> How change every first character string as Upper Case transact sql ?
>
> example
> -------
> tom and jerry
> jerry and tom
>
> result upper
>=========
> Tom And Jerry
> Jerry And Tom


If you are on SQL 2005, the absolutely best option is to write a
function in a CLR language for the task. That will be a lot more
efficient.

In T-SQL, you would have to loop over the string, looking at the present
and the previous charcater, and apply upper if the current character
is non-sepace, and the previous is space. Something like:

SELECT @prev_ch = ' ', @ix = 1, @newstr = ''
WHILE @ix <= len(@str)
BEGIN
SELECT @ch = substring(@str, @ix, 1)
IF @prev_ch = ' ' AND @ch <> ' '
SELECT @ch = upper(@ch)
SELECT @newstr = @newstr + @ch
SELECT @prev_ch = @ch, @ix = @ix + 1
END
SELECT @str = @newstr

But this very mechanical changing is not going be very nice. Title-
case is a lot more complicated than this. For instance, the correct
title case of "tom and jerry" is "Tom and Jerry". Small words like
conjunctions and prepositions are not to be capitalised. In English
that is. But is also about the only language that I know that uses
title-case. It does not seem to me that Polish uses it.

--
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

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
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 03:48 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
www.UnixAdminTalk.com