Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Parse data within one column 1

Status
Not open for further replies.

jose1024

IS-IT--Management
Jul 14, 2004
5
US
I have a column that contains city, state zip data. I need to place city and state in one column and zip in another. The field is 25 characters in length and obviously, the city varies in length within the field. I am using Transact SQL in SQL Server 2000 Query Analyzer. Any suggestions?

Examples:

current setup:
CityStateZip
ANYTOWN, NY 11123

desired result:
CityState Zip
ANYTOWN, NY 11123
 
select left(fld, len(fld) - patinindex('%[^0-9]%',reverse(fld)), right(fld, patinindex('%[^0-9]%',reverse(fld) - 1)
from tbl

Something like that.

(there are sql server forums on this sight)

======================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top