none
t-sql equivalent to substring from the right/instring?

    Question

  • Is there a t-sql equivalent to starting a substring from the right?  And an instring equivalent?  I see that there is a "right" function, to start from the right (I'm on the correct path here, yes?), but I don't know the "instring" equivalent to tell it how many characters to go.

    Thank you --

    Donna

    Monday, May 10, 2010 7:19 PM

Answers

  • Have a look at CHARINDEX, this is basically the T-SQL versino of InString.

    You might also be interested in PATINDEX.

     

    -- 

    Gert-Jan

    Monday, May 10, 2010 9:50 PM

All replies

  • Instr equivalent - SubString

    Ex: SELECT SUBSTRING('TestString' , 1, 4)

     

    Yes, you can us Right to get characters from right.

    Ex: SELECT RIGHT ('TestString' , 5)

    Res: tring

    Monday, May 10, 2010 7:23 PM
  • Not really, though you can use REVERSE function.

    You may find the following string functions helpful, though

    http://bradsruminations.blogspot.com/2010/01/handy-string-functions.html


    Premature optimization is the root of all evil in programming. (c) by Donald Knuth

    Naomi Nosonovsky, Sr. Programmer-Analyst

    My blog
    • Marked as answer by KJian_ Friday, May 14, 2010 9:10 AM
    • Unmarked as answer by CoderDonna Friday, August 05, 2011 9:05 PM
    Monday, May 10, 2010 7:39 PM
    Moderator
  • Have a look at CHARINDEX, this is basically the T-SQL versino of InString.

    You might also be interested in PATINDEX.

     

    -- 

    Gert-Jan

    Monday, May 10, 2010 9:50 PM