[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Split multiple entries in a column

Posted on 2014-01-21
4
Medium Priority
?
277 Views
Last Modified: 2014-01-22
I have data in a spreadsheet that I have imported to Access 2010.  The data has multiple columns, and in one of them there are multiple entires of names seperated by commas, and slash.  Is there a way in a querry to seperate out those names into rows with keeping all of the other row data attached?
0
Comment
Question by:smurfer1969
[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
4 Comments
 
LVL 48

Expert Comment

by:Dale Fye
ID: 39797763
Can you provide a sample of the data in that Names column?  You indicate it is separated by commas and slash, so we would need to see that to get the syntax right.

I would start out with a function that will parse the values of the Name field.
Public Function fnParse(TextToParse As String, Position As Integer, _
                        Optional Delimiter As String = ",") As Variant

    Dim strArray() As String
    
    strArray = Split(TextToParse, Delimiter)
    
    If Position < 1 Or Position > UBound(strArray) + 1 Then
        fnParse = ""
    Else
        fnParse = strArray(Position - 1)
    End If
    
End Function

Open in new window

Then I would create a table (tbl_Numbers) with a single field (intNumber) and numbers to the maximum number of names you have in any given field, plus 1.

You could then create a query that looks something like:

SELECT T.Field1, T.Field2, T.Field3, intNumber, fnParse(T.Names, intNumber, "/") as Name
FROM yourTable as T, tbl_Numbers
WHERE fnParse(T.Names, intNumber, "/") IS NOT NULL

This uses a Cartesian join (no join at all) between these two tables.  which means for every record in yourTable, you would get #n records (the # in tbl_Numbers).  By passing intNumber to fnParse() you are telling it that for this particular record, you want the Nth value from the Names field in YourTable.  And when N exceeds the number of values in your Names field, it will return a NULL, and the WHERE clause will filter those out.
0
 
LVL 48

Expert Comment

by:Dale Fye
ID: 39797765
BTW,

That code assumes that the slash you mentioned in your post separates each name and the name may have a comma to separate the last and first names.
0
 
LVL 7

Accepted Solution

by:
Steve earned 2000 total points
ID: 39797839
If you have the extra columns in the database to put it into you might.
If you want to split it in Access you can either run an update query back into the original table or a much safer bet would be to query into a new table and update from there.
You could split the entries with something like:
Mid([Transmissions]![ReportId],1,InStr(1,[Transmissions]![ReportId],".")-1) AS Expr1,

For the first section and...

Mid([Transmissions]![ReportId],InStr(1,[Transmissions]![ReportId],".")+1,InStr(1,[Transmissions]![ReportId],".")-1) AS Expr2
FROM Transmissions;

For the second.
Keep nesting another "InStr" + 1 into the start position of the previous "InStr".

InStr(1,[Transmissions]![ReportId],".")      Becomes:

InStr(InStr(1,[Transmissions]![ReportId],".") +1,[Transmissions]![ReportId],".")

Which makes it start at the next (second) "/". Adding another:

InStr(InStr(InStr(1,[Transmissions]![ReportId],".")  +1,[Transmissions]![ReportId],".") +1,[Transmissions]![ReportId],".")

Makes it start at the 3rd "/" and so on...

 Of course another option is to export it out to Excel, massage it and re-import it.
0
 
LVL 48

Expert Comment

by:Dale Fye
ID: 39800870
Good luck with that nested instr concept.

Did you try the solution I provided?  Far more elegant, and provided exactly what you asked for, a single query that provides a separate row with all of the fields the same except for the Name column.

My recommended method of dealing with this would be to assign each of those rows a unique ID and then put the multiple names associated with each row into a separate table with the RowID and the name.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

This article describes how you can use Custom Document Properties to store settings and other information in your workbook so that they will be available the next time you open the workbook.
If you need to forecast numbers -- typically for finance -- the Windows and Mac versions of Excel 2016 have a basket of tools to get the job done.
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

656 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