Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dividing a string into parts

Status
Not open for further replies.

dandot

Programmer
Jul 19, 2005
53
CA
Hi All,

I have a substring that resembles teh following:

8436/TO/AD/06.

I need the query to break this into 4 parts:
8436
TO
AD
06

Is there a function I could use?
 
Split

[small]No! No! You're not thinking ... you're only being logical.
- Neils Bohr[/small]
 
I need this in a query.
The 4 numbers must be split so I can update a table that has those 4 columns in a table independently. I didn't design this db originally btw.

I thought split breaks up the values into an array.

How could I use that function for an update query.

Example:

update table
set column 1 = 8346
column 2 = TO
column 3 = AD
column 4 = 06
 
Probably write a UDF
Code:
Public Function Splitem(TheString As String, _
                        Delim As String, _
                        ReturnIndex As Integer) As String
Dim s() As String
s = Split(TheString,Delim)
If ReturnIndex < 1 or ReturnIndex > UBound(s)+1 Then
   Splitem = ""
Else
   Splitem = s(ReturnIndex-1)
End If
End Function
Then
Code:
Select Splitem([fld],"/",1) As Col1,
       Splitem([fld],"/",2) As Col2,
       Splitem([fld],"/",3) As Col3,
       Splitem([fld],"/",4) As Col4,
etc.

[small]No! No! You're not thinking ... you're only being logical.
- Neils Bohr[/small]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top