Trying to find the first letter in row in SQL

38 views Asked by At

I have a dataset that looks at Loans by Branch and I want to find the position of the first string character by row and returning the position it is in, Below is an example of what I am looking at:

Loan #       Loan Substring 
---------------------------
1234BL           5
123BL            4
12SBL            3

I tried CHARINDEX, but I want to look at multiple substrings instead of one - any suggestions?

2

There are 2 answers

0
dami On

A regular expression would do the job, but the syntax is not standard. Which is your DBMS ?

In Oracle this would be something like SELECT REGEXP_INSTR(Loan, '[A-Z]')

0
gotqn On

You can try:

PATINDEX('%[A-Za-z]%', [Loan Substring])