help on parseing names

  • declare @n varchar(30)

    SELECT @n = 'YARBROUGH, d ALFRED'

    SELECT LEFT(@n,CHARINDEX(',',@n)-1) Last,

    PARSENAME(REPLACE(STUFF(@n,1,CHARINDEX(',',@n)+1,''),' ','.'),2) First,

    PARSENAME(REPLACE(STUFF(@n,1,CHARINDEX(',',@n)+1,''),' ','.'),1) Middle

     

    This work for 1 record but i Need to do a table,something like this. It says

    parameter is to large, I believe I need to do a while loop of some sort not sure

     

    declare @n varchar(30)

    SELECT @n = 'SELECT RTRIM(ENAME) FROM TFILP'

    SELECT LEFT(@n,CHARINDEX(',',@n)-1) Last,

    PARSENAME(REPLACE(STUFF(@n,1,CHARINDEX(',',@n)+1,''),' ','.'),2) First,

    PARSENAME(REPLACE(STUFF(@n,1,CHARINDEX(',',@n)+1,''),' ','.'),1) Middle

    THANKS

  • Did you try like below

    SELECT  LEFT((RTRIM(ENAME)),CHARINDEX(',',(RTRIM(ENAME)))-1) LastName,

     PARSENAME(REPLACE(STUFF((RTRIM(ENAME)),1,CHARINDEX(',',(RTRIM(ENAME)))+1,''),' ','.'),2) FirstName,

     PARSENAME(REPLACE(STUFF((RTRIM(ENAME)),1,CHARINDEX(',',(RTRIM(ENAME)))+1,''),' ','.'),1) MiddleName

    FROM TFILP

    Ram

     

     

     

  • Thanks that worked!!!

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply