Results 1 to 3 of 3

Thread: Breakin last naem, first name from full name

  1. #1
    Join Date
    Oct 2002
    Location
    queens
    Posts
    139

    Breakin last naem, first name from full name

    Hello all,

    I have a field called name and the data is as John, Smith.

    I need to show it as Smith John. How can I do it?

    Any help will be appriciated.

    Thanks in advance!!

  2. #2
    Join Date
    Dec 2004
    Posts
    502
    There may be a more elegant way to do it, but here is a straightforward method:

    declare @name varchar(20)
    set @name = 'John, Smith'

    SET @name = LTRIM(RTRIM(SUBSTRING(@name, CHARINDEX(',', @name, 1) +1, LEN(@name) - CHARINDEX(',', @name, 1)))) + ' ' + LTRIM(RTRIM(LEFT(@name, CHARINDEX(',', @name, 1) -1)))

    SELECT @name

  3. #3
    Join Date
    Oct 2002
    Location
    queens
    Posts
    139
    Thanks a lot! That works.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •