Re: Text manipulation in SQL

Поиск
Список
Период
Сортировка
От Josh Berkus
Тема Re: Text manipulation in SQL
Дата
Msg-id web-81558@davinci.ethosmedia.com
обсуждение исходный текст
Ответ на Text manipulation in SQL  (jim_esti@hotmail.com (Jim))
Список pgsql-sql
Jim,

> My little bit of code seems to only extract up to the first blank
> space.  Which would only work correctly if the names where only in
> two
> parts (like Jane, A).
> As I said I would like to return the NAME column in two parts (the
> letters to the right of the right most blank, and the other half).
> It seems a little trick to me.
> Anyone have any advice, hints, or solutions?

You're on exactly the right track.  Just extrapolate out the approach
you have already taken.  For example, if the names were uniformly in the
form:

Last, Initials
James, A. G. P.

Then you can easily break off the parts as you have started, you just
need to fudge the cutoff points a little:

SUBSTR(Name,1,((INSTR(', ',1,1) - 1))

Which should give you:

Last  (without comma or trailing space)
James

Then to grab the initials:

SUBSTR(Name,(INSTR(', ',1,1)+2))

Which will give you:

Initials (without comma or space).
A.G.P.

Of course, this would all be better placed in a PL/pgSQL function so
that you could test to see if the string contained ', ' before breaking
it up, look for NULL, etc.  How about posting the functions when you
have them finished?

Finally, I hope that you are doing this string parsing for *conversion*
purposes.  If you are designing a database to hold personal information,
*create seperate fields for the parts of the name!*  This is much better
DB design, and will save you many headaches in the future.

Of course, I do realize that one doesn't always have design control when
dealing with legacy systems ...

-Josh

______AGLIO DATABASE SOLUTIONS___________________________
                                       Josh Berkus
  Complete information technology      josh@agliodbs.com
   and data management solutions       (415) 565-7293
  for law firms, small businesses        fax 621-2533
    and non-profit organizations.      San Francisco

Вложения

В списке pgsql-sql по дате отправления:

Предыдущее
От: clayton cottingham
Дата:
Сообщение: Re: Re: automatic restore of database
Следующее
От: Bhuvan A
Дата:
Сообщение: Re: ConnecDB() -- couldn't send SSL negotiation packet: