Finding the Character position of nth occurence in a string.

# Thread: Finding the Character position of nth occurence in a string.

1. Raj Guest

## Finding the Character position of nth occurence in a string.

Hi Friends:

I usually run this query in Oracle to find out the position of a character in a string from first position to the nth occurence.

For example, I run the following queries in oracle to get the desire result.

---------------------------
2

---------------------------
4

---------------------------
6

---------------------------
10

Is there ay equivelant way in Transact- SQL? If not, can anybody suggest the solution?

--Raj

## Finding the Character position of nth occurence in a string. (reply)

------------
Raj at 6/15/01 11:11:14 AM

Hi Friends:

I usually run this query in Oracle to find out the position of a character in a string from first position to the nth occurence.

For example, I run the following queries in oracle to get the desire result.

---------------------------
2

---------------------------
4

---------------------------
6

---------------------------
10

Is there ay equivelant way in Transact- SQL? If not, can anybody suggest the solution?

--Raj

3. Raj Guest

## Finding the Character position of nth occurence in a string. (reply)

CHARINDEX doesn&#39;t satisfy the below results as it gives only the first occurence.

Please suggest some other way or if you feel that it can be be done thru CHARINDEX then please give some example.

--Raj

------------
Raj at 6/15/01 11:11:14 AM

Hi Friends:

I usually run this query in Oracle to find out the position of a character in a string from first position to the nth occurence.

For example, I run the following queries in oracle to get the desire result.

---------------------------
2

---------------------------
4

---------------------------
6

---------------------------
10

Is there ay equivelant way in Transact- SQL? If not, can anybody suggest the solution?

--Raj

## Finding the Character position of nth occurence in a string. (reply)

Nothing off the top of my head. You might want to programatically solve your problem using len, substring, and charindex together. The actual pseudocode involves declaring a variable designating the order of occurance. Then write some algorithm to find that occurance using the functions above.

good luck.

------------
Raj at 6/15/01 11:23:22 AM

CHARINDEX doesn&#39;t satisfy the below results as it gives only the first occurence.

Please suggest some other way or if you feel that it can be be done thru CHARINDEX then please give some example.

--Raj

------------
Raj at 6/15/01 11:11:14 AM

Hi Friends:

I usually run this query in Oracle to find out the position of a character in a string from first position to the nth occurence.

For example, I run the following queries in oracle to get the desire result.

---------------------------
2

---------------------------
4

---------------------------
6

---------------------------
10

Is there ay equivelant way in Transact- SQL? If not, can anybody suggest the solution?

--Raj

5. Raj Guest

## Finding the Character position of nth occurence in a string. (reply)

Now, I can do it.

--Raj

------------

Nothing off the top of my head. You might want to programatically solve your problem using len, substring, and charindex together. The actual pseudocode involves declaring a variable designating the order of occurance. Then write some algorithm to find that occurance using the functions above.

good luck.

------------
Raj at 6/15/01 11:23:22 AM

CHARINDEX doesn&#39;t satisfy the below results as it gives only the first occurence.

Please suggest some other way or if you feel that it can be be done thru CHARINDEX then please give some example.

--Raj

------------
Raj at 6/15/01 11:11:14 AM

Hi Friends:

I usually run this query in Oracle to find out the position of a character in a string from first position to the nth occurence.

For example, I run the following queries in oracle to get the desire result.

---------------------------
2

---------------------------
4

---------------------------
6

---------------------------
10

Is there ay equivelant way in Transact- SQL? If not, can anybody suggest the solution?

--Raj

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•