Sentence case formatting

This uses a Numbers table to find delimiter characters and build a list of token bounds.

DECLARE @strIn VARCHAR(8000) = '   some   
 
 
  local  nhs 
 
    health   authority'
 
-- replace some dodgy characters
SET @strIn = REPLACE(REPLACE(REPLACE(@strIn, '"', ''), ',', ''), '(d', '(D')
 
DECLARE @strOut VARCHAR(8000) = ''
 
;WITH delimiters AS (
  SELECT N FROM _Admin.dbo.Numbers
  WHERE N <= DATALENGTH(@strIn)
  AND SUBSTRING(@strIn, N, 1) IN (
    CHAR(10)  -- LF
  , CHAR(13)  -- CR
  , CHAR(9)   -- tab
  , CHAR(32)  -- space
  )
  UNION SELECT 0
  UNION SELECT DATALENGTH(@strIn) + 1
), seq AS (
  SELECT 
    ROW_NUMBER() OVER (
      ORDER BY N
    ) AS SeqNo
  , N
  FROM delimiters
)
SELECT 
  @strOut += 
    CASE 
      WHEN _end.N - 1 - _start.N > 0 THEN 
        CASE UPPER(SUBSTRING(@strIn, _start.N + 1, _end.N - 1 - _start.N))  -- capitalise certain tokens
          WHEN 'NHS' THEN 'NHS'
          WHEN 'CCG' THEN 'CCG'
          WHEN 'LHB' THEN 'LHB'
          WHEN 'MSGH' THEN 'MSGH'
          WHEN 'PCT' THEN 'PCT'
          WHEN 'PCG' THEN 'PCG'
          WHEN 'HQ' THEN 'HQ'
          ELSE   -- otherwise follow initial capital with lowercase suffix
              UPPER(SUBSTRING(@strIn, _start.N + 1, 1)) 
            + LOWER(SUBSTRING(@strIn, _start.N + 2, _end.N - 2 - _start.N)) 
        END + ' '
      ELSE ''  -- eliminate successive delimiters
    END
FROM seq _start
  INNER JOIN seq _end ON _start.SeqNo + 1 = _end.SeqNo
 
SELECT @strOut