November 4, 2014 at 3:45 pm
I have a column of data that has this /Product_Images/small/1/10032.png , I tried using RIGHT with CHARINDEX and was unable to get the results i was looking for.
Can anyone help me just retrieve the everything after the last / so i get just the image.
Best Regards,
Cory
November 4, 2014 at 3:49 pm
This might help.
SELECT string, RIGHT( string, CHARINDEX( '/', REVERSE(string)) - 1)
FROM (VALUES('/Product_Images/small/1/10032.png'))x(string)
November 4, 2014 at 4:06 pm
So my code is something like this in a long select statement
select RIGHT([Items(Webex)].[image], CHARINDEX( '/', REVERSE([Items(Webex)].[image])) - 1) AS ImageName from PTS_Data
I tried this and it returned an error
Invalid length parameter passed to the RIGHT function.
November 4, 2014 at 4:10 pm
I forgot to include the safety net. 😉
SELECT string, RIGHT( string, CHARINDEX( '/', REVERSE('/' + string)) - 1)
FROM (VALUES('/Product_Images/small/1/10032.png'), ('JustImage.png'))x(string)
November 4, 2014 at 4:25 pm
Thats perfect, I didnt think of using reverse. Thanks a million.
Best Regards,
Cory
Viewing 5 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply