Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
arkiboys
Master Smack Fu Yak Hacker
1433 Posts |
Posted - 2013-10-08 : 09:09:08
|
Hello,From the following string, how do I get the name of the file including the extension i.e. .csv\\servername\foldername\filename_20131001.csvSo to get: "filename_20131001.csv"Thank you |
|
James K
Master Smack Fu Yak Hacker
3873 Posts |
Posted - 2013-10-08 : 09:19:40
|
[code]DECLARE @x VARCHAR(255) = '\\servername\foldername\filename_20131001.csv'SELECT REVERSE(LEFT(REVERSE(@x),CHARINDEX('\',REVERSE(@x)+'\')-1));[/code] |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2013-10-08 : 09:29:04
|
orDECLARE @x VARCHAR(255) = '\\servername\foldername\filename_20131001.csv'SELECT RIGHT((@x),CHARINDEX('\',reverse(@x))-1); MadhivananFailing to plan is Planning to fail |
|
|
James K
Master Smack Fu Yak Hacker
3873 Posts |
Posted - 2013-10-08 : 09:47:28
|
quote: Originally posted by madhivanan orDECLARE @x VARCHAR(255) = '\\servername\foldername\filename_20131001.csv'SELECT RIGHT((@x),CHARINDEX('\',reverse(@x))-1); MadhivananFailing to plan is Planning to fail
Shorter and sweeter, Madhivanan!Adding a "+'\'" in case there are records with no path:RIGHT((@x),CHARINDEX('\',reverse(@x)+'\')-1) |
|
|
arkiboys
Master Smack Fu Yak Hacker
1433 Posts |
Posted - 2013-10-08 : 10:15:02
|
Thank you all. |
|
|
djj55
Constraint Violating Yak Guru
352 Posts |
Posted - 2013-10-08 : 10:18:59
|
James, I hope I can remember the '\' tip! Would have never thought of it.djj |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2013-10-08 : 13:36:06
|
quote: Originally posted by James K
quote: Originally posted by madhivanan orDECLARE @x VARCHAR(255) = '\\servername\foldername\filename_20131001.csv'SELECT RIGHT((@x),CHARINDEX('\',reverse(@x))-1); MadhivananFailing to plan is Planning to fail
Shorter and sweeter, Madhivanan!Adding a "+'\'" in case there are records with no path:RIGHT((@x),CHARINDEX('\',reverse(@x)+'\')-1)
Yes. Thanks MadhivananFailing to plan is Planning to fail |
|
|
|
|
|
|
|