?
Solved

PATINDEX vs. InStr function

Posted on 2014-07-30
6
Medium Priority
?
1,130 Views
Last Modified: 2014-08-20
Hello Folks,

I would like to have result in MS-Access using InStr function like we can have in SQL Server using PATINDEX.
As per below example, the result (0021) I would like from below string  

DECLARE @var NVarChar(1000)= 'H:\_Data\Mohit\277_State_V12_Modem\2007\Opeartion_Research_Pooling\U.S\1955_01_0021_V3PLAN_TF_00000_United_Arab_Emirates.pdf'
SELECT PATINDEX('%[_][0-9][0-9][0-9][0-9][_]%',@var)
SELECT SUBSTRING(@var,PATINDEX('%[_][0-9][0-9][0-9][0-9][_]%',@var)+1, 4)

Could you please assist on it in MS-Access using InStr function as result might be change but pattern will be same as used in PATINDEX aforesaid?

Best Regards,
Mohit Pandit
0
Comment
Question by:MohitPandit
[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
  • 3
  • 3
6 Comments
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 40230027
in Access you can use
Select * from tableX
Where [FieldName] Like "*[_][0-9][0-9][0-9][0-9][_]*"

or
Select * from tableX
Where [FieldName] Like "%[_][0-9][0-9][0-9][0-9][_]%"
0
 
LVL 5

Author Comment

by:MohitPandit
ID: 40231194
I need result in SELECT statement as column. I don't want to filter.
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 40231495
you will need a UDF to do this in Access, is this an option?
0
Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

 
LVL 5

Author Comment

by:MohitPandit
ID: 40271862
Yes, I need this SELECT statement in Access. Is it possible to identify pattern like we use to do with PATINDEX?
0
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 2000 total points
ID: 40272323
place this codes in a regular module


Function Whatever(xRef As String)
Dim x, j
If xRef & "" = "" Then Whatever = "": Exit Function
x = Split(xRef, "_")
For j = 0 To UBound(x)
    If IsNumeric(x(j)) And Len(x(j)) = 4 Then
        Whatever = x(j)
        Exit For
    End If
Next
End Function

to use, pass the string to the function

?whatever ("H:\_Data\Mohit\277_State_V12_Modem\2007\Opeartion_Research_Pooling\U.S\1955_01_0021_V3PLAN_TF_00000_United_Arab_Emirates.pdf")
0
 
LVL 5

Author Closing Comment

by:MohitPandit
ID: 40274252
thanks
0

Featured Post

Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

Question has a verified solution.

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

Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

777 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