473,383 Members | 1,813 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

How to parse a record with multiple fields

I have a table that contains log entries.
The table has two columns, the first column is a timestamp and the second column contains the data I need to parse. What I have to do is seperate the three fields in the second column into three columns.
Here is an example of two rows of data from the second column;

(TA:606:Duplicate Entry For ItemId SerialId ModelNo [12350901] [123456086632509] [2016] )
(TA:606:Duplicate Entry For ItemId SerialId ModelNo [45685470] [957125352146255] [14] )

I am not too familiar with Access 2000 but reviewing the forums I attempted to use instr with left and right functions to extract. Didn't work too well for me.
I think the brackets were the problem....
Feb 26 '08 #1
10 2614
Delerna
1,134 Expert 1GB
just to clarify the question, what should the two records of data look like after running the query on them?

my guess is
12350901,123456086632509,2016
45685470,957125352146255,14

but im only guessing
Feb 26 '08 #2
missinglinq
3,532 Expert 2GB
Like Delerna said, we need to see what kind of results you want. Also, in the two examples below

(TA:606:Duplicate Entry For ItemId SerialId ModelNo [12350901] [123456086632509] [2016] )
(TA:606:Duplicate Entry For ItemId SerialId ModelNo [45685470] [957125352146255] [14] )

are the hilited fields always the same number of characters in length or do they vary?

Welcome to TheScripts!

Linq ;0)>
Feb 26 '08 #3
ADezii
8,834 Expert 8TB
I have a table that contains log entries.
The table has two columns, the first column is a timestamp and the second column contains the data I need to parse. What I have to do is seperate the three fields in the second column into three columns.
Here is an example of two rows of data from the second column;

(TA:606:Duplicate Entry For ItemId SerialId ModelNo [12350901] [123456086632509] [2016] )
(TA:606:Duplicate Entry For ItemId SerialId ModelNo [45685470] [957125352146255] [14] )

I am not too familiar with Access 2000 but reviewing the forums I attempted to use instr with left and right functions to extract. Didn't work too well for me.
I think the brackets were the problem....
As long as the data to be parsed remains within brackets ([ ]), and a single space exists between the data elements and at the end of the 3rd element, then it becomes a fairly simple matter. Assuming the 2nd Column is in a Field named [Field_Test], which is in a Table named tblTest, then it becomes a Query with three Calculated Fields calling 3 simple Functions:
Expand|Select|Wrap|Line Numbers
  1. SELECT tblTest.Field_Test, fParseString1([Field_Test]) AS Field1, fParseString2([Field_Test]) AS Field2, fParseString3([Field_Test]) AS Field3
  2. FROM tblTest
  3. WHERE (((tblTest.Field_Test) Is Not Null));
Expand|Select|Wrap|Line Numbers
  1. Public Function fParseString1(strString As String)
  2. Dim varParsedString As Variant
  3.  
  4. varParsedString = Split(strString, "[")
  5.  
  6. 'The 2nd Element in the Array will contain the 1st Parsed Field
  7. fParseString1 = Left$(varParsedString(1), Len(varParsedString(1)) - 2)
  8. End Function
Expand|Select|Wrap|Line Numbers
  1. Public Function fParseString2(strString2 As String)
  2. Dim varParsedString As Variant
  3.  
  4. varParsedString = Split(strString2, "[")
  5.  
  6. 'The 3rd Element in the Array will contain the 2nd Parsed Field
  7. fParseString2 = Left$(varParsedString(2), Len(varParsedString(2)) - 2)
  8. End Function
Expand|Select|Wrap|Line Numbers
  1. Public Function fParseString3(strString3 As String)
  2. Dim varParsedString As Variant
  3.  
  4. varParsedString = Split(strString3, "[")
  5.  
  6. 'The 4th Element in the Array will contain the 3rd Parsed Field
  7. fParseString3 = Left$(varParsedString(3), Len(varParsedString(3)) - 3)
  8. End Function
OUTPUT (not showing [Field_Test], the entire String):
Expand|Select|Wrap|Line Numbers
  1. Field1        Field2            Field3
  2. 12350901    123456086632509      2016
  3. 45685470    957125352146255      14
  4. 000000        1111                222222222222214               
  5.  
NOTE: Last Record was a Test Record, the other 2 used the supplied data.
Feb 26 '08 #4
just to clarify the question, what should the two records of data look like after running the query on them?

my guess is
12350901,123456086632509,2016
45685470,957125352146255,14

but im only guessing
Thanks for replying so quickly, the data should be put into a new table with three columns containing the data you have seperated by commas.
Feb 27 '08 #5
Like Delerna said, we need to see what kind of results you want. Also, in the two examples below

(TA:606:Duplicate Entry For ItemId SerialId ModelNo [12350901] [123456086632509] [2016] )
(TA:606:Duplicate Entry For ItemId SerialId ModelNo [45685470] [957125352146255] [14] )

are the hilited fields always the same number of characters in length or do they vary?

Welcome to TheScripts!

Linq ;0)>
The first highlighted field is always 8 characters (VARCHAR2) and the second field will range from 12 to 16 characters (VARCHAR2). This example contains numbers, but they will contain alphanumerics.
Feb 27 '08 #6
As long as the data to be parsed remains within brackets ([ ]), and a single space exists between the data elements and at the end of the 3rd element, then it becomes a fairly simple matter. Assuming the 2nd Column is in a Field named [Field_Test], which is in a Table named tblTest, then it becomes a Query with three Calculated Fields calling 3 simple Functions:
Expand|Select|Wrap|Line Numbers
  1. SELECT tblTest.Field_Test, fParseString1([Field_Test]) AS Field1, fParseString2([Field_Test]) AS Field2, fParseString3([Field_Test]) AS Field3
  2. FROM tblTest
  3. WHERE (((tblTest.Field_Test) Is Not Null));
Expand|Select|Wrap|Line Numbers
  1. Public Function fParseString1(strString As String)
  2. Dim varParsedString As Variant
  3.  
  4. varParsedString = Split(strString, "[")
  5.  
  6. 'The 2nd Element in the Array will contain the 1st Parsed Field
  7. fParseString1 = Left$(varParsedString(1), Len(varParsedString(1)) - 2)
  8. End Function
Expand|Select|Wrap|Line Numbers
  1. Public Function fParseString2(strString2 As String)
  2. Dim varParsedString As Variant
  3.  
  4. varParsedString = Split(strString2, "[")
  5.  
  6. 'The 3rd Element in the Array will contain the 2nd Parsed Field
  7. fParseString2 = Left$(varParsedString(2), Len(varParsedString(2)) - 2)
  8. End Function
Expand|Select|Wrap|Line Numbers
  1. Public Function fParseString3(strString3 As String)
  2. Dim varParsedString As Variant
  3.  
  4. varParsedString = Split(strString3, "[")
  5.  
  6. 'The 4th Element in the Array will contain the 3rd Parsed Field
  7. fParseString3 = Left$(varParsedString(3), Len(varParsedString(3)) - 3)
  8. End Function
OUTPUT (not showing [Field_Test], the entire String):
Expand|Select|Wrap|Line Numbers
  1. Field1        Field2            Field3
  2. 12350901    123456086632509      2016
  3. 45685470    957125352146255      14
  4. 000000        1111                222222222222214               
  5.  
NOTE: Last Record was a Test Record, the other 2 used the supplied data.

Great!!!! I am new to Access. Where would I inject this code?
Feb 27 '08 #7
ADezii
8,834 Expert 8TB
Great!!!! I am new to Access. Where would I inject this code?
The 'Public' Functions would be place into a Standard Code Module. The SQL can be copied and pasted into the SQL View on a New Query.
Feb 27 '08 #8
NeoPa
32,556 Expert Mod 16PB
Define a public function Element() in a standard code module :
Expand|Select|Wrap|Line Numbers
  1. Public Function Element(strWhole As String, intElement As Integer) As String
  2.   Element = Split(Split(strWhole, "[")(intElement), "]")(0)
  3. End Function
This would be called using :
Expand|Select|Wrap|Line Numbers
  1. SELECT Field_Test,
  2.        Element([Field_Test], 1) AS Field1,
  3.        Element([Field_Test], 2) AS Field2,
  4.        Element([Field_Test], 3) AS Field3
  5. FROM tblTest
  6. WHERE ([Field_Test] IS NOT NULL)
Feb 28 '08 #9
ADezii
8,834 Expert 8TB
Define a public function Element() in a standard code module :
Expand|Select|Wrap|Line Numbers
  1. Public Function Element(strWhole As String, intElement As Integer) As String
  2.   Element = Split(Split(strWhole, "[")(intElement), "]")(0)
  3. End Function
This would be called using :
Expand|Select|Wrap|Line Numbers
  1. SELECT Field_Test,
  2.        Element([Field_Test], 1) AS Field1,
  3.        Element([Field_Test], 2) AS Field2,
  4.        Element([Field_Test], 3) AS Field3
  5. FROM tblTest
  6. WHERE ([Field_Test] IS NOT NULL)
Hello NeoPa, I really must congratulate you on quite an elegant, innovative, and simplistic solution. A single Function Procedure instead of one, a winner every time! What made you think of the "Double Split" idea? Again, job well done!
Feb 28 '08 #10
NeoPa
32,556 Expert Mod 16PB
Thanks ADezii :)
I was planning on a Split using "] [" then I saw it wouldn't work very well. Decided "[" was the one to use, then it occurred to me that I could also strip the extraneous bits with another simple Split().

PS. I WAS pleased with myself I must admit ]:)
Feb 28 '08 #11

Sign in to post your reply or Sign up for a free account.

Similar topics

19
by: Peter A. Schott | last post by:
I've got a file that seems to come across more like a dictionary from what I can tell. Something like the following format: ###,1,val_1,2,val_2,3,val_3,5,val_5,10,val_10...
10
by: Mark | last post by:
I have a table about people containing 25 fields. The table contains the usual fields - first, last, address, city, state and zip. There is no primary key. These fields all have data with the...
5
by: Theresa Hancock via AccessMonster.com | last post by:
I have an Excel table I need to import into Access. The name is entered into one field "Name". I'd like to have two fields in Access, FirstName and LastName. How do I do this. -- Message posted...
5
by: Ross A. Finlayson | last post by:
Hi, I'm scratching together an Access database. The development box is Office 95, the deployment box Office 2003. So anyways I am griping about forms and global variables. Say for example...
11
by: hoopsho | last post by:
Hi Everyone, I am trying to write a program that does a few things very fast and with efficient use of memory... a) I need to parse a space-delimited file that is really large, upwards fo a...
5
by: D. Shane Fowlkes | last post by:
This may be a very basic question but it's something I've never done before. I've looked at a couple of my favorite sites and books and can't find an answer either. I can write a Function to...
6
by: ApexData | last post by:
I have 2 tables: Table1 and Table2. Neither one has a primary key because each table will only have 1-record. My form is a SingleForm unbound with tabs (my desire here). Using this form, in...
7
by: john | last post by:
In my form I have a master table and a details table linked 1xM. I can search through the whole parent table but I also like to be able to search through the child table fields to find parent...
2
by: fburn | last post by:
I need some help with an error I'm getting using php 5.2.5 running on linux. I receive an error: Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.