5> DECLARE @LastName VarChar(25), @SpaceIndex TinyInt
6> SET @LastName = 'mc donald'
7> -- Find space in name:
8> SET @SpaceIndex = CHARINDEX(' ', @LastName)
9> IF @SpaceIndex > 0
10> SELECT UPPER(LEFT(@LastName, 1))
11> + LOWER(SUBSTRING(@LastName, 2, @SpaceIndex - 1))
12> + UPPER(SUBSTRING(@LastName, @SpaceIndex + 1, 1))
13> + LOWER(SUBSTRING(@LastName, @SpaceIndex + 2, LEN(@LastName)))
14> ELSE
15> SELECT UPPER(LEFT(@LastName, 1))
16> + LOWER(SUBSTRING(@LastName, 2, LEN(@LastName)))
17> GO
----------------------------------------------------
Mc Donald
(1 rows affected)
1>
|