Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 camel case

Author  Topic 

sqldev6363
Yak Posting Veteran

54 Posts

Posted - 2009-03-17 : 14:10:35
Ignore the above topic

i have a column name col1 with value 'PRODUCT GROUP'. While i am displaying the result of that column i need to display like this

Product Group

First letter should be capital for PRODUCT and G should be Capital for the word GROUP, Remain should be small

PRODUCT GROUP is one word, there is a space in "PRODUCT GROUP"


dev

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2009-03-17 : 14:40:06
formatting issues are usually handled by the presentation layer. Can you do it there?

If not, Is it always two word values or could there be more than 2 words?
Should the rule be to always capitalize a letter following a space?
Do you have to deal with names like these - which would need rules beyond the space thing:
W.C. Fields
Baron von Trap
Micky O'Brien

check out this topic:
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=56499

Be One with the Optimizer
TG
Go to Top of Page

sqldev6363
Yak Posting Veteran

54 Posts

Posted - 2009-03-17 : 14:43:49
It should be done fron backend only. Always two words only like this

PRODUCT GROUP.

Please help me out on this.

Regards
SQLDev

quote:
Originally posted by TG

formatting issues are usually handled by the presentation layer. Can you do it there?

If not, Is it always two word values or could there be more than 2 words?
Should the rule be to always capitalize a letter following a space?
Do you have to deal with names like these - which would need rules beyond the space thing:
W.C. Fields
Baron von Trap
Micky O'Brien

check out this topic:
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=56499

Be One with the Optimizer
TG



dev
Go to Top of Page

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2009-03-17 : 15:00:29
Here's one way - it's ugly but it works:

select upper(left(col1, 1)) +
stuff(lower(substring(col1, 2, len(col1))), charindex(' ', col1), 1, upper(substring(col1, charindex(' ', col1)+1, 1)))
from (--This is your table
select 'PRODUCT GROUP' as col1 union all
select 'ANOTHER ONE'
) as yourTable

output:
Product Group
Another One


Be One with the Optimizer
TG
Go to Top of Page

sqldev6363
Yak Posting Veteran

54 Posts

Posted - 2009-03-17 : 19:34:27
Thanks alot

dev
Go to Top of Page

mfemenel
Professor Frink

1421 Posts

Posted - 2009-03-17 : 20:32:36
Just because I thought this was interesting and since it doesn't have to be dynamic. Having said that I would think you could just do a case statement and be done with the silliness. If you ever got into a situation where this was common I'd look into a CLR function which would be better suited to this type of thing.

declare @testvar varchar(20)='PRODUCT GROUP'

select CHARINDEX(@testvar,' ')
select REPLACE(REPLACE(@testvar,'RODUCT','roduct'),'ROUP','roup')

Mike
"oh, that monkey is going to pay"
Go to Top of Page

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2009-03-17 : 22:53:04
quote:
Originally posted by mfemenel

Just because I thought this was interesting and since it doesn't have to be dynamic. Having said that I would think you could just do a case statement and be done with the silliness. If you ever got into a situation where this was common I'd look into a CLR function which would be better suited to this type of thing.

declare @testvar varchar(20)='PRODUCT GROUP'

select CHARINDEX(@testvar,' ')
select REPLACE(REPLACE(@testvar,'RODUCT','roduct'),'ROUP','roup')


Ha! I guess if they know that the value is always 'PRODUCT GROUP' then why not just:

select 'Product Group' as Col1

Be One with the Optimizer
TG
Go to Top of Page
   

- Advertisement -