繁体   English   中英

SQL查询以检索路径和文件名

[英]Sql Query to Retrieve Path and file Name

我需要从数据库列中检索带有扩展名的文件名。

范例:来自c:\\abc\\bde\\hyr\\gff\\test.txt

我需要得到像test.txt这样的结果

c:\\abc\\bde\\hyr\\gff

请帮忙

谢谢

你可以试试看

SELECT REVERSE(LEFT(REVERSE(columnName),CHARINDEX('\',REVERSE(columnName))-1)) AS FileName,
REVERSE(RIGHT(REVERSE(columnName),LEN(REVERSE(columnName)) - CHARINDEX('\',REVERSE(columnName)))) AS Directory

SubString的替代方法是使用以下内容,并使用CharIndexReverse

Select  Left([FilePath], Len([FilePath]) - CharIndex('\', Reverse([FilePath])))     [FolderPath],
        Right('\' + [FilePath], CharIndex('\', Reverse('\' + [FilePath])) - (1))    [FileName]

这会将最后一个\\之后的所有内容作为FileName,并将之前的所有内容作为FolderPath。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM