I came back to this thread today because I was trying to proper case some stuff around here. I needed to exclude tokens that contain at least a single digit but all other tokens should be init caps.
I made a slight modification to Dwain's that worked well for my purposes.
CREATE FUNCTION [dbo].[ProperCaseWithNumbers]
(
@StrIn VARCHAR(255)
)
RETURNS TABLE WITH SCHEMABINDING
AS
RETURN
SELECT STUFF((
SELECT CASE
WHEN split.Item LIKE '%[0-9]%'
THEN ' ' + split.Item
ELSE ' ' + Upper(LEFT(split.Item, 1)) + Lower(Substring(split.Item, 2, 255))
END AS word
FROM dbo.Delimitedsplit8k(@StrIn, ' ') split
FOR XML PATH('')
,TYPE
).value('.', 'varchar(255)'), 1, 1, '') AS ProperCased
We have some data coming from the mainframe and it is all caps but I need to make this data more "user friendly". Here is an example of this one in action.
declare @MyVals table (SeriesName varchar(25))
insert @MyVals
select '9400 SERIES' union all
select '9760 SERIES' union all
select 'ADE360 SERIES' union all
select 'CUSTOM' union all
select 'M16360 SERIES' union all
select 'N1260 SERIES' union all
select 'N3160 SERIES' union all
select 'PA360 SERIES' union all
select 'S260 SERIES'
select *
from @MyVals v
cross apply dbo.ProperCaseWithNumbers(v.SeriesName)
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/