Click here to Skip to main content
15,790,565 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a table with 399 records that have a full path in the the Filename column. I can trim the filename to the last '\' using the following;
select replace(Part.Filename, rtrim(Part.Filename, replace(Part.Filename, '\', '')), '') from Part

What I want to do is replace the filename with the trim value for each record.
i.e., If I have:

replace with:

Any help appreciated!

What I have tried:

I tried:
update Part set Filename = (select replace(Part.Filename, rtrim(Part.Filename, replace(Part.Filename, '\', '')), '') from Part)

but it replaced all records with a single value.
Updated 8-Sep-23 5:31am
PIEBALDconsult 7-Sep-23 14:01pm    
Maybe use INSTR() to find the backslashes, but I think you would then have to loop until there are none.

I believe you want to do a multiple-row update.
Multiple-row updates are difficult -- the syntax is odd.
However, in recent times a new thing has arisen : CTE (Common Table Expression).

Here's the official sqlite doc on that including an example that you should be able to manipulate for your purposes: UPDATE[^]
Share this answer
Maciej Los 7-Sep-23 14:36pm    

Believe it or not I did this and it worked;

update Part set Filename = (select replace(Part.Filename, rtrim(Part.Filename, replace(Part.Filename, '\', '')), ''))

by removing the from Part from the query it updates nicely!

Thanks everyone for your input!
Share this answer
PIEBALDconsult 7-Sep-23 16:45pm    
Please don't try to answer your own question, just use the Improve question button at add detail.

But seriously, may I bother you with something which is causing me some trouble?
Richard Deeming 8-Sep-23 3:49am    
There's nothing wrong with answering your own question, so long as:

a) it's actually an answer;
b) it's not a copy of someone else's answer; and
c) you didn't already know the answer when you posted the question, and only posted both to gain the rep points.

This answer is fine on all three counts. :)
Mike Hankey 7-Sep-23 16:47pm    
Maciej Los 11-Sep-23 15:23pm    

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900