ms access sql expression to seperate data

kevinh2320

Board Regular
Joined
May 13, 2016
Messages
61
I have a column in my MS ACCESS query called Field1 with data similar to what's shown below. I'm looking for SQL expressions to separate this information into 3 separate AS columns. So, looking at the top row that would be .00 then .00 and then BILLING ACTIVATED. Thanks!

Field1
.00 .00 BILLING ACTIVATED
.00 .00 BILLING ACTIVATED
.00 6,500.00 BILLING ACTIVATED
.00 .00 CLOSED
5,800.00 .00 BILLING ACTIVATED
.00 325.00 REACTIVATED
.00 .00 LEASE TERMINATED
.00 .00 RELINQUISHED
.00 .00 PENDING/SUSPEND/I
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
SELECT SplitString(column, ' ', 0), SplitString(column, ' ', 1), SplitString(column, ' ', 2)

Code:
Public Function SplitString(str As String, delimiter As String, column As Integer) As String
    Dim strArr() As String
    strArr = Split(str, delimiter)
    
    If column > 1 Then
        For i = 2 To UBound(strArr)
            SplitString = SplitString & strArr(i) & " "
        Next
        
        SplitString = Trim(SplitString)
    Else
        SplitString = strArr(column)
    End If
End Function
 
Upvote 0
For a non-VBA solution, you could use Access Query String Functions, like this:
FirstField: Trim(Left([Field1],InStr([Field1]," ")))
SecondField: Trim(Left(Mid([Field1],Len([FirstField])+2),InStr(Mid([Field1],Len([FirstField])+2)," ")))
ThirdField: Trim(Mid([Field1],InStr(InStr([Field1]," ")+1,[Field1]," ")))


Though I like the use of a User Defined Function too (a bit cleaner)!
 
Upvote 0
Not sure which solution you went with, but glad you got it working!
 
Upvote 0

Forum statistics

Threads
1,214,647
Messages
6,120,722
Members
448,987
Latest member
marion_davis

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top