Skip to content

Commit e5058d6

Browse files
authored
Merge pull request #209688 from seesharprun/patch-2
Cosmos DB | Updated SQL query INDEX_OF code samples
2 parents 3a5e1b6 + 6931681 commit e5058d6

File tree

1 file changed

+41
-28
lines changed

1 file changed

+41
-28
lines changed

articles/cosmos-db/sql/sql-query-index-of.md

Lines changed: 41 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5,49 +5,62 @@ author: ginamr
55
ms.service: cosmos-db
66
ms.subservice: cosmosdb-sql
77
ms.topic: conceptual
8-
ms.date: 09/13/2019
8+
ms.date: 08/30/2022
99
ms.author: girobins
1010
ms.custom: query-reference
1111
---
12+
1213
# INDEX_OF (Azure Cosmos DB)
14+
1315
[!INCLUDE[appliesto-sql-api](../includes/appliesto-sql-api.md)]
1416

15-
Returns the starting position of the first occurrence of the second string expression within the first specified string expression, or -1 if the string is not found.
16-
17+
Returns the starting position of the first occurrence of the second string expression within the first specified string expression, or `-1` if the string isn't found.
18+
1719
## Syntax
18-
20+
1921
```sql
20-
INDEX_OF(<str_expr1>, <str_expr2> [, <numeric_expr>])
21-
```
22-
22+
INDEX_OF(<str_expr1>, <str_expr2> [, <numeric_expr>])
23+
```
24+
2325
## Arguments
24-
25-
*str_expr1*
26-
Is the string expression to be searched.
27-
28-
*str_expr2*
29-
Is the string expression to search for.
26+
27+
*str_expr1*
28+
Is the string expression to be searched.
29+
30+
*str_expr2*
31+
Is the string expression to search for.
3032

3133
*numeric_expr*
32-
Optional numeric expression that sets the position the search will start. The first position in *str_expr1* is 0.
33-
34+
Optional numeric expression that sets the position the search will start. The first position in *str_expr1* is 0.
35+
3436
## Return types
35-
36-
Returns a numeric expression.
37-
37+
38+
Returns a numeric expression.
39+
3840
## Examples
39-
40-
The following example returns the index of various substrings inside "abc".
41-
41+
42+
The following example returns the index of various substrings inside "abc".
43+
4244
```sql
43-
SELECT INDEX_OF("abc", "ab") AS i1, INDEX_OF("abc", "b") AS i2, INDEX_OF("abc", "c") AS i3
44-
```
45-
46-
Here is the result set.
47-
45+
SELECT
46+
INDEX_OF("abc", "ab") AS index_of_prefix,
47+
INDEX_OF("abc", "b") AS index_of_middle,
48+
INDEX_OF("abc", "c") AS index_of_last,
49+
INDEX_OF("abc", "d") AS index_of_missing
50+
```
51+
52+
Here's the result set.
53+
4854
```json
49-
[{"i1": 0, "i2": 1, "i3": -1}]
50-
```
55+
[
56+
{
57+
"index_of_prefix": 0,
58+
"index_of_middle": 1,
59+
"index_of_last": 2,
60+
"index_of_missing": -1
61+
}
62+
]
63+
```
5164

5265
## Next steps
5366

0 commit comments

Comments
 (0)