July 21, 2017 at 11:36 am
from the given string need to extract the filename:
\\CORP-BI-DEV-01\Temp\TIVExplorer\vzwprices-2017-06-21.json
How can i get tihis?
July 21, 2017 at 11:40 am
komal145 - Friday, July 21, 2017 11:36 AMfrom the given string need to extract the filename:\\CORP-BI-DEV-01\Temp\TIVExplorer\vzwprices-2017-06-21.json
How can i get tihis?
With extension or without extension? Will the path be similar or a different number of directories can be part of it?
July 21, 2017 at 11:41 am
Luis Cazares - Friday, July 21, 2017 11:40 AMkomal145 - Friday, July 21, 2017 11:36 AMfrom the given string need to extract the filename:\\CORP-BI-DEV-01\Temp\TIVExplorer\vzwprices-2017-06-21.json
How can i get tihis?
With extension or without extension? Will the path be similar or a different number of directories can be part of it?
Just file name with extension :vzwprices-2017-06-21.json
July 21, 2017 at 11:42 am
Luis Cazares - Friday, July 21, 2017 11:40 AMkomal145 - Friday, July 21, 2017 11:36 AMfrom the given string need to extract the filename:\\CORP-BI-DEV-01\Temp\TIVExplorer\vzwprices-2017-06-21.json
How can i get tihis?
With extension or without extension? Will the path be similar or a different number of directories can be part of it?
Just file name with extension :vzwprices-2017-06-21.json
will that matters as i need filename ..some files have no extension, i need to get those too.
July 21, 2017 at 11:42 am
SELECT reverse(left(reverse('\\CORP-BI-DEV-01\Temp\TIVExplorer\vzwprices-2017-06-21.json'), charindex('\', reverse('\\CORP-BI-DEV-01\Temp\TIVExplorer\vzwprices-2017-06-21.json')) -1))
July 21, 2017 at 11:48 am
some similar posts from you
https://www.sqlservercentral.com/Forums/1818860/need-to-extract-text-from-given-string
https://www.sqlservercentral.com/Forums/1882790/Extract-String
________________________________________________________________
you can lead a user to data....but you cannot make them think
and remember....every day is a school day
July 21, 2017 at 11:51 am
do a reverse lookup on "\", elementary and you'll find many examples around
😎
July 21, 2017 at 11:58 am
robin.pryor - Friday, July 21, 2017 11:42 AMSELECT reverse(left(reverse('\\CORP-BI-DEV-01\Temp\TIVExplorer\vzwprices-2017-06-21.json'), charindex('\', reverse('\\CORP-BI-DEV-01\Temp\TIVExplorer\vzwprices-2017-06-21.json')) -1))
There's no need to use 2 reverse functions. This is important because this is a slow function.
DECLARE @String varchar(255) = '\\CORP-BI-DEV-01\Temp\TIVExplorer\vzwprices-2017-06-21.json';
SELECT RIGHT( @String, CHARINDEX( '\', REVERSE(@String) + '\') - 1);
July 21, 2017 at 12:21 pm
Luis Cazares - Friday, July 21, 2017 11:58 AMrobin.pryor - Friday, July 21, 2017 11:42 AMSELECT reverse(left(reverse('\\CORP-BI-DEV-01\Temp\TIVExplorer\vzwprices-2017-06-21.json'), charindex('\', reverse('\\CORP-BI-DEV-01\Temp\TIVExplorer\vzwprices-2017-06-21.json')) -1))There's no need to use 2 reverse functions. This is important because this is a slow function.
DECLARE @String varchar(255) = '\\CORP-BI-DEV-01\Temp\TIVExplorer\vzwprices-2017-06-21.json';SELECT RIGHT( @String, CHARINDEX( '\', REVERSE(@String) + '\') - 1);
Thanks it works.
July 21, 2017 at 12:24 pm
komal145 - Friday, July 21, 2017 12:21 PMThanks it works.
Do you understand why and how it works?
July 21, 2017 at 12:53 pm
Luis Cazares - Friday, July 21, 2017 12:24 PMkomal145 - Friday, July 21, 2017 12:21 PMThanks it works.
Do you understand why and how it works?
Yes. I was using charindex and right but "reverse" function is much more useful.
July 21, 2017 at 1:24 pm
Luis Cazares - Friday, July 21, 2017 12:24 PMkomal145 - Friday, July 21, 2017 12:21 PMThanks it works.
Do you understand why and how it works?
Took me just a moment to figure out why you concatenated a '\' after you reversed the string. What if there wasn't a leading '\' in the string.
Viewing 12 posts - 1 through 11 (of 11 total)
You must be logged in to reply to this topic. Login to reply