query value between COMMAS

dastr

Registered User.
Local time
Today, 13:04
Joined
Apr 1, 2012
Messages
43
Hi all,
I have the following data:
Article Sizes
Shoes 40,41,42,43
Tshirt s,m,x,xl
Jeans 30,32,34

I was wondering is there any query that would easily give me the size between the SECOND and the THIRD comma – for shoes – 41; for tshirt – M; for jeans – 32?
Any help will be highly appreciated,
Thx
 
But then you have things to experiment with, you have Left, right, Len and InStr functions. What problem you are facing.
 
For starters, your examples are between the first and second commas, not second and third. In any case check out the Split() function.
 
One of the many ways:
Code:
Function fSecondValue(ByVal Origin As String, ByVal separator As String) As String
  fSecondValue = Mid(Origin,[COLOR=Red] InStr(1, Origin, separator)[/COLOR] + 1, _
  [COLOR=Blue]InStr(InStr(1, Origin, separator) + 1, Origin, separator)[/COLOR] - _
  InStr(1, Origin, separator) - 1)
End Function
InStr(1, Origin, separator) position of first comma
InStr(InStr(1, Origin, separator) + 1, Origin, separator) position of second comma

RequiredValue = fSecondValue(Sizes,",")
 
Last edited:
Like pbaldy said, the split command does the work in a single line:

Code:
?split("Shoes 40,41,42,43",",")(1)
returns 41

if you want the shoes go first:
Code:
?split("Shoes 40,41,42,43"," ")(0) & " - "& split("Shoes 40,41,42,43",",")(1)
returns Shoes - 41

HTH:D
 

Users who are viewing this thread

Back
Top Bottom