Friday, March 23, 2012

How to use substring with starting point?

Hi all,

I want to select a column which is store email address. How to use the substring function from starting point'@.' to end of string?

Here is my syntax :

select substring(emailaddress, [what syntax] ,len(emailaddress)) from table

Thanks!

See CharIndex in Books on Line. It will give you that location of any string within a string.

CHARINDEX

Returns the starting position of the specified expression in a character string.

Syntax

CHARINDEX(expression1,expression2 [,start_location])

Arguments

expression1

Is an expression containing the sequence of characters to be found.expression1 is an expression of the short character data type category.

expression2

Is an expression, usually a column searched for the specified sequence.expression2is of the character string data type category.

start_location

Is the character position to start searching forexpression1 inexpression2. Ifstart_location is not given, is a negative number, or is zero, the search starts at the beginning ofexpression2.

|||Thanks!

No comments:

Post a Comment