Solved

Removing parts of a string from a variable

Posted on 2011-03-10
6
309 Views
Last Modified: 2012-05-11
The code is below works great for removing a variable called state from my variable called location.. I populate the @state variable from the information passed in to the @location variable and use it to "extract" it from the variable so all I have left in street.. ( I also do the same for city and zip).. Here is the problem:

When @Location is populated it could be populated with NC or North Carolina or WV or West Virginia or WVirginia etc.. When I populate the @State variable it goes through an outside process that takes whatever of those values and "normalizes" them to a 2 letter state.. So North Carolina becomes NC and Westvirginia becomes WV.. So when I go to remove them from @Location via the code below it does not always work..Removing the Zip is no problem so I can do that first and then state is next in line.. If the last word in my string is NC or NorthCarolina or North Carolina or NCarolina HOW can I remove it? I guess I could look for the space before the last word but what if someone puts a comma in between the city and state and sometimes they don't? Suggestions?( BTW I can not change the outside process)
set @location = replace(@location, @State, '')

Open in new window

0
Comment
Question by:cheryl9063
  • 3
  • 3
6 Comments
 
LVL 33

Expert Comment

by:paulmacd
Comment Utility
This will be nigh impossible to do with any certainty.  That's why so many forms break this information out into separate fields, and why state/country selection is almost always done with a dropdown list.

That said, can't you "normalize" @location with the same routine you use to "normalize" @state?  If you only "normalize" the last 20 or so characters of the @location, you should avoid hitting streets with state names (though you may still "normalzie" some cities with state names).
0
 
LVL 1

Author Comment

by:cheryl9063
Comment Utility
No.. These are the requirements.. I have no say on front end and no say on MelissaData.. I just need to strip the state out of the string..I may have to do three set statments possible? First remove zip, then and commas and then some kind of function that finds the last word in the string and removes it..
0
 
LVL 33

Accepted Solution

by:
paulmacd earned 500 total points
Comment Utility
That seems feasible, but if the user lives in "North Carolina", you'll strip the "Carolina" but leave the "North".  And you won't know you need to remove the "North" because the "North" may belong to the street name.  There's no fool-proof way to accomplish the task you've been given (unless the front-end people relent and give you more normalized data).
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 1

Author Comment

by:cheryl9063
Comment Utility
OK.. So lets think of it this way.. What code will  Parse from the end of the variable to the first space and give me that word.. For example.. If this is what I have left

5220 michaux rd greensboro north... I want to pull greensboro out.. What code can I use to do that?

0
 
LVL 1

Author Closing Comment

by:cheryl9063
Comment Utility
Thanks!
0
 
LVL 33

Expert Comment

by:paulmacd
Comment Utility
You're welcome.  Sorry I couldn't be more help.
0

Featured Post

Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
SQL 2012 Syntax Error 5 22
Write a function 5 24
SQL to update characters in table column 6 25
SQL Transaction logs 8 6
Naughty Me. While I was changing the database name from DB1 to DB_PROD1 (yep it's not real database name ^v^), I changed the database name and notified my application fellows that I did it. They turn on the application, and everything is working. A …
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now