我有一个包含存储路径和文件名的数据的列,如下所示:
Quit_Smoking/Include_curriculum_and_learning_activities/ACTIVITY_Q_020214.pdf
Stay_SunSmart_every_day/Education_and_learning_activities/
ACTIVITY_S_Sid_Activity_Book_11213.pdf
Stay_SunSmart_every_day/Education_and_learning_activities/
ACTIVITY_S_SS_Colouring_Book_11213.pdf
我们已将文件名拆分为自己的列,需要将其从此列中删除。我遇到的问题是文件名长度并非都是特定的,所以我正常解决此问题的方式(使用len()
和right()
)赢了工作。如何删除列中最后/
右侧的所有内容?
答案 0 :(得分:1)
declare @S nvarchar(100) = 'Quit_Smoking/Include_curriculum_and_learning_activities/ACTIVITY_Q_020214.pdf'
select reverse(stuff(reverse(@S), 1, charindex('/', reverse(@S)), ''))
答案 1 :(得分:0)
DECLARE @S NVARCHAR(100) = 'Quit_Smoking/Include_curriculum_and_learning_activities/ACTIVITY_Q_020214.pdf';
SELECT SUBSTRING(@S, 1, LEN(@S) - CHARINDEX('/', REVERSE(@S)));