Home Forums SQL Server 2012 SQL Server 2012 - T-SQL Convert name field from Colunm1: FirstName LastName to Column2 as LastName, FirstName RE: Convert name field from Colunm1: FirstName LastName to Column2 as LastName, FirstName

  • Warnings were made, so here's a possibility.

    SELECT SUBSTRING(FullName, CHARINDEX(' ', FullName) + 1, 8000) + ', '
      + LEFT(FullName, CHARINDEX(' ', FullName) - 1)
    FROM (VALUES
    ('John Doe'),
    ('Joe Doe'),
    ('Jane Doe'))x(FullName)

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2