Antonio Papa Antonio Papa - 6 months ago 25
SQL Question

Split string and take last element

I have a table with this values:

Articles/Search/ArtMID/2681/ArticleID/2218/Diet.aspx
OurStory/MeettheFoodieandtheMD.aspx
TheFood/OurMenu.aspx


I want to get this

Diet.aspx
MeettheFoodieandtheMD.aspx
OurMenu.aspx


How can i do this?

Answer

The way to do it in SQL :

SELECT SUBSTRING( string , LEN(string) -  CHARINDEX('/',REVERSE(string)) + 2  , LEN(string)  ) FROM SAMPLE;

JSFiddle here http://sqlfiddle.com/#!3/41ead/11

Comments