Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in SQL by (20.3k points)

Given an email address column, I need to find the position of the @ sign for the substring.

What is the index of function, for strings in T-SQL?

Looking for something that returns the position of a substring within a string.

in C#

var s = "abcde";

s.IndexOf('c'); // yields 2

1 Answer

0 votes
by (40.7k points)

Use CHARINDEX in your code like this: 

select CHARINDEX('@', '[email protected]')

-----------

8(1 row(s) affected)

Or else use below code:

select CHARINDEX('c', 'abcde')

-----------

3 (1 row(s) affected)

Related questions

Browse Categories

...