SQL - Select statement using LastIndex
-
22-07-2019 - |
Question
I have a resultset which has ProductURL stored :
accessoires/abc/285/P187654
accessoires/abc/285/D18765432
accessoires/abc/285/A1876543
I need to get the final part of the URL i.e. anything that is after the final '/' that appears in the URL.
I have a function which gives me the LASTINDEX :
SELECT [LAST_INDEX] (ProductURL,'/')
But how do I run a Select statement with this function inside a substring:
SELECT Substring(ProductURL,SELECT [LAST_INDEX] (ProductURL,'/'),len(ProductURL))
from data
This does not seem to work? Is there another way to do this?
Solution
Just get rid of the SELECT
:
SELECT Substring(ProductURL, [LAST_INDEX] (ProductURL, '/'), len(ProductURL))
FROM data
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow