I have the file names with the below format:
123.672-filename.pdf
want to get just the filename.pdf part which is right after the Hyphen. upto end.in this case is pdf file.
I have over 500k filenames want to extract the filenames.
Thanks a lot for the helpful info.
declare @fn varchar(255) = '123.672-filename.pdf'
select reverse(@fn), CHARINDEX('.', reverse(@fn)), left(@fn, len(@fn) -CHARINDEX('.', reverse(@fn)))
--The " + '-' " is just in case there is no - in the original string.
SELECT RIGHT(string, CHARINDEX('-', REVERSE(string) + '-') - 1)
FROM (
SELECT '123.672-filename.pdf' AS string
) AS test_data
Thanks a lot it worked. thank you.
or
declare @fn varchar(255) = '123.672-filename.pdf'
select substring(@fn,charindex('-',@fn)+1,len(@fn))