Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Help Parsing CityState
Message
De
12/02/2010 04:28:35
 
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Divers
Thread ID:
01448886
Message ID:
01448890
Vues:
48
Greetings,

This is an Oracle command which will show the state only. Perhaps you can adapt it to SQL Server.

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


>I have a column called CityState. It has 14 rows:
>
>
>CityState
>------------------------------------
>BREA  CA
>SAN DIEGO CA
>NORTHBROOK IL
>SAN DIEGO
>ENCINITAS
>VISTA
>ENCINITAS
>POWAY
>CARLSBAD CA
>LINCOLN  NE
>SAN MARCOS CA
>OCEANSIDE
>ENCINITAS
>OCEANSIDE
>
>I'm trying to split out the city & state:
>
>SELECT	CityState,
>		CASE 
>			WHEN LBCMS.dbo.OCCURS(' ', CityState) = 0 THEN CityState 
>			WHEN LBCMS.dbo.OCCURS(' ', CityState) = 1 THEN SUBSTRING(CityState, 1, LBCMS.dbo.AT(' ', CityState, 1))
>			WHEN LBCMS.dbo.OCCURS(' ', CityState) = 2 THEN SUBSTRING(CityState, LBCMS.dbo.AT(' ', CityState, 2), 200)
>		END AS City
>	FROM ContactInfo1
>	 WHERE CityState IS NOT NULL
>
>
>I'm getting this:
>
>
>CA
>CA
>NORTHBROOK 
>SAN 
>ENCINITAS
>VISTA
>ENCINITAS
>POWAY
>CARLSBAD 
>NE
>CA
>OCEANSIDE
>ENCINITAS
>OCEANSIDE
>
>Anyone see what's wrong?
William Chadbourne
Senior Programmer/Analyst
State of Maine - DAFS App Team

Oracle - When you care enough to use the very best!!
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform