Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

SQL Pull data from a variable out of another variable

Posted on 2011-03-08
3
Medium Priority
?
246 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
3 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 2000 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
This month, Experts Exchange sat down with resident SQL expert, Jim Horn, for an in-depth look into the makings of a successful career in SQL.
Integration Management Part 2
Screencast - Getting to Know the Pipeline

972 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