Solved

Parsing one column into 3 columns

Posted on 2012-04-02
4
237 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
  • 2
  • 2
4 Comments
 
LVL 1

Accepted Solution

by:
mainmind83 earned 500 total points
Comment Utility
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
Comment Utility
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
Comment Utility
Create a SQL procedure
0
 

Author Comment

by:knamc
Comment Utility
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

'Between' is such a common word we rarely think about it but in SQL it has a very specific definition we should be aware of. While most database vendors will have their own unique phrases to describe it (see references at end) the concept in common …
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.​
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

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