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
 General SQL Server Forums
 New to SQL Server Programming
 how to convert selected text into Capital letters

Author  Topic 

mohan123
Constraint Violating Yak Guru

252 Posts

Posted - 2013-10-24 : 02:28:46
i have string where i need to convert them into Capital text in required string only

i have written query to do this using Charindex it is finding only one how to go for 2nd one i am only finding the 2 nd word through index how to find other words also

select UPPER(LEFT(SUBSTRING('AHRQ utilization flag',CHARINDEX(' ','AHRQ utilization flag',0)+1,
len('AHRQ utilization flag')),1))


for Example :

have a great day

my desired out put :

Have A Great Day


how to do this one .......suggest me


P.V.P.MOhan

VeeranjaneyuluAnnapureddy
Posting Yak Master

169 Posts

Posted - 2013-10-24 : 02:53:43
CREATE FUNCTION InitialCap(@String VARCHAR(8000))
RETURNS VARCHAR(8000)
AS
BEGIN

DECLARE @Position INT;

SELECT @String = STUFF(LOWER(@String),1,1,UPPER(LEFT(@String,1))) COLLATE Latin1_General_Bin,
@Position = PATINDEX('%[^A-Za-z''][a-z]%',@String COLLATE Latin1_General_Bin);

WHILE @Position > 0
SELECT @String = STUFF(@String,@Position,2,UPPER(SUBSTRING(@String,@Position,2))) COLLATE Latin1_General_Bin,
@Position = PATINDEX('%[^A-Za-z''][a-z]%',@String COLLATE Latin1_General_Bin);

RETURN @String;
END ;

veeranjaneyulu
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2013-10-24 : 04:05:36
Also read this http://beyondrelational.com/modules/2/blogs/70/posts/10901/tsql-initcap-function-convert-a-string-to-proper-case.aspx

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -