Solved

SQL Pull data from a variable out of another variable

Posted on 2011-03-08
3
239 Views
Last Modified: 2012-05-11
OK.. I have a variable called @Location.. The data in it is this: 500 Main St Greensboro NC 27401..

I have the following variables called @City, @State and @Zip.. Each of them has already been populated with the information above.. For example @City is populated with Greensboro and @State is populated with NC etc... I was able to populate the three variables from @Location.. However now I need to strip out the City, State and Zip from @Location so all I have left in @Location is 500 Main St...What is the best way?
0
Comment
Question by:cheryl9063
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 35070223
something like:
set @location = replace(@location, @city, '')
set @location = replace(@location, @Zip, '')
set @location = replace(@location, @State, '')

Open in new window

0
 
LVL 32

Expert Comment

by:awking00
ID: 35070275
You may want to rtrim angelIII's solution to remove unnecessary spaces at the end.
set @location = rtrim(@location)
0
 
LVL 1

Author Closing Comment

by:cheryl9063
ID: 35070330
Thanks!
0

Featured Post

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

710 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