Results 1 to 2 of 2

Thread: substring help

  1. #1
    Join Date
    Apr 2004
    Posts
    101

    Unanswered: substring help

    Hi,
    please help me in developing query to satisfy this...
    i have table called test and the table data looks like this.

    col1
    123.abc
    1.ab
    12.cba

    the query needs to return all rows data after . the result set should return this

    abc
    ab
    cba

    appreciate your help..
    thanks
    sskris

  2. #2
    Join Date
    Jan 2005
    Location
    TempDb
    Posts
    228
    The following only returns rows that have a value following a '.':

    Declare @t Table (Col1 varchar(10))
    Insert @t
    Select '123.abc'
    Union
    Select '1.ab'
    Union
    Select '12.cba'
    Union
    Select '12'
    Union
    Select '.'
    Union
    Select '123.'

    Select Col1, Substring(Col1, CharIndex('.', Col1, 1) + 1, Len(Col1) - CharIndex('.', Col1, 1))
    From @t
    Where CharIndex('.', Col1, 1) != 0 And ( Len(Col1) - CharIndex('.', Col1, 1) > 0)
    Last edited by MaxA; 02-04-05 at 23:43.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •