?
Solved

Split multiple entries in a column

Posted on 2014-01-21
4
Medium Priority
?
276 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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

This article helps those who get the 0xc004d307 error when trying to rearm (reset the license) Office 2013 in a Virtual Desktop Infrastructure (VDI) and/or those trying to prep the master image for Microsoft Key Management (KMS) activation. (i.e.- C…
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.
The viewer will learn how to simulate a series of sales calls dependent on a single skill level and learn how to simulate a series of sales calls dependent on two skill levels. Simulating Independent Sales Calls: Enter .75 into cell C2 – “skill leve…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses

764 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