Question: I have this column

```
NAME
John Stephenson
James Martin
Anna Corelia

```

How I can select this column to this?

```
NAME
Stephenson, John
Martin, James
Corelia, Anna 

```

Answer: 
One way

```
;with test(name) as (
    select 'John Stephenson' union all
    select 'James Martin' union all
    select 'Anna J. Corelia' union all
    select 'BOBBYTABLES'
)
select
case when charindex(' ', name) = 0 then name  
else right(name, charindex(' ', reverse(name)) - 1) + ', ' + substring(name, 1, len(name) - charindex(' ', reverse(name))) end
from test

(No column name)
Stephenson, John
Martin, James
Corelia, Anna J.
BOBBYTABLES

```
There is no a single trim function but you can 

```
 select   ltrim(rtrim(colname)) from tablename 

```

which will TRIM both sides.

but what you need is:

```
declare @name varchar(300) ='Stephenson John';
Select  

Substring(@name, 1,Charindex(' ', @name)-1) +
', '  +
Substring(@name, Charindex(' ', @name)+1, LEN(@name))
 as name

```

Sorry I miss post