Solved

Parsing one column into 3 columns

Posted on 2012-04-02
4
243 Views
Last Modified: 2012-05-31
I have an address column that I need to break into 5 columns.  The data is seperated with comma,s Here is what the data looks like:

General Motors, 30001 Van Dyke Ave, Warren, MI, 48090

and need it split into seperate columns.

Name
Street
City
State
Zip
0
Comment
Question by:knamc
[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
  • 2
  • 2
4 Comments
 
LVL 1

Accepted Solution

by:
mainmind83 earned 500 total points
ID: 37797913
I prefer do this task with C# to prevent errores but:

http://sqltutorials.blogspot.com.es/2007/09/sql-function-split.html
0
 

Author Comment

by:knamc
ID: 37798762
DECLARE @NextString NVARCHAR(40)
DECLARE @Pos INT
DECLARE @NextPos INT
DECLARE @String NVARCHAR(40)
DECLARE @Delimiter NVARCHAR(40)

SET @String = 'General Motors, 30001 Van Dyke Ave, Warren, MI, 48090'
SET @Delimiter = ','
SET @String = @String + @Delimiter
SET @Pos = charindex(@Delimiter,@String)

WHILE (@pos <> 0)
BEGIN
SET @NextString = substring(@String,1,@Pos - 1)
SELECT @NextString -- Show Results
SET @String = substring(@String,@pos+1,len(@String))
SET @pos = charindex(@Delimiter,@String)
END

This returns:

General Motors

30001 Van Dyke Ave

I need columns:

General Motors         30001 Van Dyke Ave        Warren       MI         48090

This works for a single value but how can I incorporate it into a select statement used to insert into a customer address table?
0
 
LVL 1

Expert Comment

by:mainmind83
ID: 37799431
Create a SQL procedure
0
 

Author Comment

by:knamc
ID: 37803164
I am new to this function and a SQL newbie,  all I am looking for is a little guidance on how to get the output I need and how I can have it load from a table based on the address field I have.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

732 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