Visual basic support “InStr” Function, which Returns the starting position of the specified expression in a character string.
To perform same task in SQL Server used CHARINDEX Function.
“CharIndex” Function is equivalent to “InStr” Function of SQL Server.
Example 1:
select Phone,charindex('-',Phone) from customers
Result
| 030-0074321 | 4 |
| (5) 555-4729 | 8 |
| (5) 555-3932 | 8 |
| (171) 555-7788 | 10 |
| 0921-12 34 65 | 5 |
| 0621-08460 | 5 |
| 88.60.15.31 | 0 |
You can also specify start position
Example 2:
select Phone,charindex('-',Phone,5) from customers
here start position is 5.
Result
| 030-0074321 | 0 |
| (5) 555-4729 | 8 |
| (5) 555-3932 | 8 |
| (171) 555-7788 | 10 |
| 0921-12 34 65 | 5 |
| 0621-08460 | 5 |
| 88.60.15.31 | 0 |

1 comment:
excelent! Lo que buscaba
Post a Comment