Tuesday, May 20, 2008

InStr Function in SQL Server

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:

Anonymous said...

excelent! Lo que buscaba

Most Recent Post

Subscribe Blog via Email

Enter your email address:



Disclaimers:We have tried hard to provide accurate information, as a user, you agree that you bear sole responsibility for your own decisions to use any programs, documents, source code, tips, articles or any other information provided on this Blog.
Page copy protected against web site content infringement by Copyscape