String iteration to compare with ascii value in sql?

I have a column containing rows

as

id fruit

1  apple
2  mango
3  banana
4  grapes
5  watermelon

I need to iterate over the fruit string to find out where the ascii value is a, which is 97.

as in id = 1 apple contains 'a'=97, so I want to print position of character ain all lines, comparing it with the ascii value of 97.

can someone tell me how to iterate over each row to compare with ascii 97 value?

+3
source share
1 answer
SELECT CHARINDEX((CHAR(97), fruit)
FROM MyTable

Here we use a function CHARINDEXthat gives the first character position within the string and a function CHAR()that returns the character assigned to the specified ascii value.

+3
source

All Articles