Add Space In Front of A Capital Letter Within Connected Words



create table test (reports varchar(50))

Insert into test values('admissionPage'),('topHighCost'),('requestedReportsZu')
;with mycte as (
Select reports, substring(reports,d.num,1) s 
,Case when ASCII(SUBSTRING(reports,d.num,1)) between 65 and 90  Then 1 else 0 End IsCapital
from test
cross apply(values(1),(2),(3),(4),(5),(6),(7),(8),(9),(10),(11),(12),(13),(14),(15),(16),(17),(18),(19),(20)) d(num)
)

,mycte1 as (
SELECT Distinct reports = (
SELECT   Case When IsCapital=1 Then ' '+s Else s End
 FROM mycte m
 WHERE m.reports=m1.reports
 FOR XML PATH(''))
 FROM mycte m1)


Select  reports from mycte1

drop table test

 
Advertisements


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s