Fnd 2nd occourance of a string in a Memo Field

99封情书 提交于 2019-12-25 04:27:16

问题


I have a memo field called "Worklog". My table name is: MissingT. I would like to run a query which can find a specific string and get the next 6 digits following that specific string.

The string would look like below:

Status: Work in Progress
 Submitted: December 5, 2014 - 8:44:53 AM EST
 Approval Status: Approved
 Date Approved: December 5, 2014 - 8:44:53 AM EST
  
 SECTION 1 - REQUESTER PROFILE
 User ID: xxx111
 Name: Some, Name
 Phone #: 999-999-999
 Region: Canada
  
 SECTION 2 - AUTHORIZED INDIVIDUAL PROFILE
 User ID: xxx222
 Name: Some, name2
 Phone #:999-999-9999
 Title: Manager

I want the query to get the user id under section 2. My current query finds the User ID under section 1 and gets the 6 strings following it (xxx111). How can I move the query to get the 2nd occurrence of string "User ID" and the 6 strings following it.

UPDATE MissingT SET MissingT.AuthManager = mid([Worklog],(InStr([Worklog],'User ID: ')+8),7)
WHERE (((MissingT.[worklog]) Like  "*" & 'User ID:' & "*"  ));

回答1:


I am not 100% sure how efficient this could be, however I would suggest you to have a play around with this.

UPDATE 
    MissingT 
SET 
    MissingT.AuthManager = SplSplit([Worklog], 'User ID: ', 1, 7)
WHERE 
    MissingT.[worklog] Like  "*User ID:*";

The SplSplit is a UDF, which is something like,

Public Function SplSplit(inpStr As String, _
                         findStr As String, _
                         inVar As Integer, _
                         lenVar As Integer)

    SplSplit = Left(Split(inpStr, findStr)(inVar), lenVar)

    'If you want it to be ONE based then change it to the following. 
    'SplSplit = Left(Split(inpStr, findStr)(inVar+1), lenVar)'
End Function

inpStr is the Memo String you pass, findStr is the string patter you want to use to break it into multiple sections, inVar is the location of the data you are looking for, finally lenVar is the length you need to collect.

NOTE: The inVar is still ZERO based, if you want ONE based, then change the inVar as inVar + 1 in the code.

The Split function will break the huge memo field into smaller chunks of data, based on the identifier, in your case 'User ID: '. Since we are only concerned about the second User ID, we simply use that index (as Split give a zero based array of split data).

The correct solution however; would be to forget about this horrendous Memo field and create a log table with appropriate status code and fields.



来源:https://stackoverflow.com/questions/27903227/fnd-2nd-occourance-of-a-string-in-a-memo-field

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!