Solved

extract string from column

Posted on 2012-03-26
6
387 Views
Last Modified: 2012-08-13
I have the following situation:

I have a column that is contains the following data (string):

A0000AXYZTI00
A0000A12345TI00
etc..

I need to obtain the string value that starts with the 2nd 'A' and ends before the 'T'
So in this case it would be AXYX abd A12345. Sometimes the length between the 2nd A and the T varies. Is there an easy way of doing this with some sort of string function?

Many thanks.
0
Comment
Question by:BauwensER
[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
6 Comments
 
LVL 10

Accepted Solution

by:
Tobias earned 500 total points
ID: 37770032
Dear,

Something like this should work :

text = "A0000AXYZTI00"

long_text = Len(text)

pos_t = Instr (1, text , "T")  
pos_2nd_a = Instr (2, text , "A")  

value = Mid("A0000AXYZTI00", pos_2nd_a+1, pos_t-pos_2nd_a)

Open in new window

0
 
LVL 39

Expert Comment

by:Pratima Pharande
ID: 37770060
in query
Select Mid("A0000AXYZTI00", Instr (2, text , "A")  +1 ,Instr (1, text , "TI00") )
0
 

Author Comment

by:BauwensER
ID: 37770073
I just tried value: Mid([MFAnumber], Instr (2, [MFAnumber], "A")  +1 ,Instr (1, [MFAnumber], "TI00") ) but it does not return the right values.
0
Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 
LVL 29

Expert Comment

by:Badotz
ID: 37770098
Something like this, perhaps:
Function Splitter(str)
    Dim ra
    Dim rb

    ra = Split(str, "T") '' "T" segment(s)
    rb = Split(ra(0), "A") '' "A" segment(s)

    Splitter = "A" & rb(2) '' Return value
End Function

MsgBox Splitter("A0000AXYZTI00") '' "AXYZ"
MsgBox Splitter("A0000A12345TI00") '' "A12345"

Open in new window

0
 
LVL 10

Expert Comment

by:Tobias
ID: 37770118
Select Mid([MFAnumber], Instr(2, [MFAnumber], "A")+1 ,Instr(1,[MFAnumber], "T")- Instr(2, [MFAnumber], "A")-1)
0
 
LVL 29

Expert Comment

by:Badotz
ID: 37770189
You want concise? You get concise!

Put this in a module:
Function Splitter(ByVal str As String) As String
    Splitter = "A" & Split(Split(str, "T")(0), "A")(2)
End Function

Open in new window

Assume

A1 = "A0000AXYZTI00"

and

A2 = "A0000A12345TI00"

Enter
=Splitter(A1)

Open in new window

into B1 and copy it down to B2.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SQL Query logic question 14 71
CISCO WIFI 6 73
question about a text field with default value 5 31
Speed up Select Top n... Query 9 37
Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…

738 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