/* ------------------------ My Meta Content Here SEO ------------------------ */

Pages

Main Menu

Friday, September 27, 2019

Capitalize only the first letter of each word of each sentence in SQL Server

BEGIN TRAN UPDATE T_MST_Skills SET Name =  stuff((select ' '+upper(left(T3.V, 1))+lower(stuff(T3.V, 1, 1, ''))
       from (select cast(replace((select Name as '*' for xml path('')), ' ', '') as xml).query('.')) as T1(X)
         cross apply T1.X.nodes('text()') as T2(X)
         cross apply (select T2.X.value('.', 'varchar(1000)')) as T3(V)
       for xml path(''), type
       ).value('text()[1]', 'varchar(1000)'), 1, 1, '') from T_MST_Skills where [Name] not like '%(%' and [Name] not like '%.%';

Rollback:

select Name,stuff((
       select ' '+upper(left(T3.V, 1))+lower(stuff(T3.V, 1, 1, ''))
       from (select cast(replace((select Name as '*' for xml path('')), ' ', '') as xml).query('.')) as T1(X)
         cross apply T1.X.nodes('text()') as T2(X)
         cross apply (select T2.X.value('.', 'varchar(1000)')) as T3(V)
       for xml path(''), type
       ).value('text()[1]', 'varchar(1000)'), 1, 1, '') as [Capitalize first letter only] from T_MST_Skills where [Name] not like '%(%' and [Name] not like '%.%';

No comments:

Post a Comment

My Blog List