【发布时间】:2017-08-25 16:02:45
【问题描述】:
我有十年来一直在将具有绝对路径的文件名插入数据库的旧代码。正如您可能已经猜到的那样,路径已经更改了很多次,现在我的列中包含许多不同位置的文件名。 我想:
- 更新此列以仅包含文件名 + 扩展名
- 从那时起将代码更改为仅插入文件名 + 扩展名。
- 更改 getter 以获取这个新的 db 列,并期望它只是文件名 + 扩展名,并附加从属性文件中检索到的完整路径
这就是DistListName 列现在在 db 中的样子:
DistListName
D:/REPOSITORY/DistributionListFiles/DistListFile-201312241253420087_1.csv
D:\docs\upload\DocAccess\Projects\ET\Distribution\ID_LE36A12-8-17-520-edited-6rows.csv
D:\docs\upload\Temp\5thdistributionList.csv
D:\docs\upload\DocAccess\Projects\ET\Distribution\APO-FPO - 3rows.csv
D:\docs\upload\Documents and Settings\mark\Desktop\4thdistributionList.csv
D:\docs\upload\Distribution\Printed Labels\2004 July\21 jul 04.csv
D:\docs\upload\200704191301190609\TestZipCode\4thdistributionList.csv
D:\docs\upload\Documents and Settings\patel\Desktop\attachments\distributionList_25.csv
D:\docs\upload\200704230652240281\Documents and Settings\omar\Desktop\ 1-1M-34 change\ID_01T06229100000R_070305102408.csv
D:\docs\upload\200704251628340140\TestZipCode\4thdistributionList.csv
b
NULL
C:\FILES\upload\201110041235580647\fakepath\ID_2 US locations2_100311a.csv
C:\FILES\upload\201111091019410135\Documents and Settings\leslo\Desktop\DPG CSV\Good CSVs\3 Jobs - FY-12-TESTING -.csv
我有显示最终结果的 SELECT 语句,但我不确定如何将其转换为 UPDATE 语句:
select
CASE WHEN CHARINDEX('/', REPLACE(DistListName,'\','/')) > 0 THEN
RIGHT(REPLACE(DistListName,'\','/'), CHARINDEX('/', REVERSE(REPLACE(DistListName,'\','/'))) -1) ELSE DistListName END file_name
FROM myTable
输出:
DistListName
DistListFile-201312241253420087_1.csv
ID_LE36A12-8-17-520-edited-6rows.csv
5thdistributionList.csv
APO-FPO - 3rows.csv
4thdistributionList.csv
21 jul 04.csv
4thdistributionList.csv
distributionList_25.csv
ID_01T06229100000R_070305102408.csv
4thdistributionList.csv
b
NULL
ID_2 US locations2_100311a.csv
3 Jobs - FY-12-TESTING -.csv
在我的代码中,我只期望 db 列中的文件名 + 扩展名:
public static String getUploadPath(String dbFileName)
{
ResourceBundle bundle = ResourceBundle.getBundle("fileLocations");
return bundle.getString("DistributionListFilesPath") + dbFileName;
}
fileLocations.properties
DistributionListFilesPath=D:/projectFiles/DistributionListFiles/
谁能帮我把这个 SELECT 语句改成 UPDATE 语句?
【问题讨论】:
标签: sql sql-server tsql sql-update