基本上,我想要做的是在句点之后取文件名中的任何内容并移动到另一个名为extension的列,如果没有句点将文本带到扩展列
SELECT
[UserProfile12_7-512-1mb].FileName,
Right([Filename], Len([Filename])-InStrRev([Filename],".")) AS Extension,
[UserProfile12_7-512-1mb].ComputerName,
[UserProfile12_7-512-1mb].KB
FROM
[UserProfile12_7-512-1mb]
;
答案 0 :(得分:1)
您可以组合SQL函数REVERSE和CHARINDEX来复制相同的逻辑。
DECLARE @FileName VARCHAR(255) = 'C:\MyFolder\MyFile.csv';
-- Extract file extension.
SELECT
RIGHT(@FileName, CHARINDEX('.', REVERSE(@FileName)) - 1) AS Ext
;
返回:
Ext
----
csv
修改强>
以下是应用于示例查询的技术:
SELECT
[UserProfile12_7-512-1mb].FileName,
RIGHT([Filename], CHARINDEX('.', REVERSE([Filename])) - 1) AS Extension,
[UserProfile12_7-512-1mb].ComputerName,
[UserProfile12_7-512-1mb].KB
FROM
[UserProfile12_7-512-1mb]
;