Getting string part based on some character in MSSQL

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • shivendra
    New Member
    • Aug 2007
    • 1

    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.nara yan@rediffmail. com". I need only rediffmail.com now. Means to say get the string after the '@'

    PLZ help me

    Thank You,
    Shivendra
  • edukulla
    New Member
    • Aug 2007
    • 3

    #2
    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.nara yan@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(columnna me)
    FROM tablename
    WHERE 'Write your condition here'
    Now, you can use the query below to return the
    SELECT SUBSTRING(colum nname, string_index, (col_length - string_index))
    from tablename WHERE 'Write your condition here'

    Hope this helps!!
    Thanks!
    Santhosh

    Comment

    Working...