Monday, March 26, 2012

Getting string part based on some character in MSSQL

Hi,
I have one Req where I have to get the portion of the string ,like I have one e-Mail iD "shivendra.narayan@.rediffmail.com". I need only rediffmail.com now. Means to say get the string after the '@.'

PLZ help me

Thank You,
Shivendra

Quote:

Originally Posted by shivendra

Hi,
I have one Req where I have to get the portion of the string ,like I have one e-Mail iD "shivendra.narayan@.rediffmail.com". I need only rediffmail.com now. Means to say get the string after the '@.'

PLZ help me

Thank You,
Shivendra


-----------

Declare string_index int
Declare col_length int
select string_index = PATINDEX('%@.%', columnname),
col_length = length(columnname)
FROM tablename
WHERE 'Write your condition here'
Now, you can use the query below to return the
SELECT SUBSTRING(columnname, string_index, (col_length - string_index))
from tablename WHERE 'Write your condition here'

Hope this helps!!
Thanks!
Santhosh

No comments:

Post a Comment