Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
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.
Ignore the above topici have a column name col1 with value 'PRODUCT GROUP'. While i am displaying the result of that column i need to display like thisProduct GroupFirst letter should be capital for PRODUCT and G should be Capital for the word GROUP, Remain should be smallPRODUCT 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. FieldsBaron von TrapMicky O'Briencheck out this topic:http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=56499Be One with the OptimizerTG
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 thisPRODUCT GROUP.Please help me out on this.RegardsSQLDev
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. FieldsBaron von TrapMicky O'Briencheck out this topic:http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=56499Be One with the OptimizerTG
dev
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 yourTableoutput:Product GroupAnother One
Be One with the OptimizerTG
sqldev6363
Yak Posting Veteran
54 Posts
Posted - 2009-03-17 : 19:34:27
Thanks alotdev
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"
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 Col1Be One with the OptimizerTG