开发者

update table access

开发者 https://www.devze.com 2023-02-13 23:31 出处:网络
I have a table in which i want to update a multiple rows. the row data is like this: Cars/Audi/Norway/model1/sports.Jpeg

I have a table in which i want to update a multiple rows. the row data is like this:

Cars/Audi/Norway/model1/sports.Jpeg
Cars/Audi/Norway/model1/classic.Jpeg
Cars/Audi/Norway/model1/v8.Jpeg
Cars/Audi/Norway/model1/v6.Jpeg

now i want only to update the model1, let say i want to make it model two. so how can i do it in just one query? i am using this query:

string path="some string";
string name = "some string";

("select replace(filepath,'" + path + "','" + name + "')

so it seem like

    Cars/Audi/Norway/model10/sports.Jpeg
    Cars/Audi/开发者_如何学CNorway/model10/classic.Jpeg
    Cars/Audi/Norway/model10/v8.Jpeg
    Cars/Audi/Norway/model10/v6.Jpeg

any idea?


UPDATE CarImages
SET Path=Replace(Path,'/Model1/','/Model10/');

Assuming that the table is called 'CarImages' and the field you want to update is called Path.


replace is only available when working within Access itself, it is a VBA function, not Jet/ACE. You will need something like:

SELECT Left([field1],InStr([field1],"/model1")-1) 
    & "/model2" 
    & Mid([field1],InStr([field1],"/model1")+Len("/model1")) AS result
FROM Table1;
0

精彩评论

暂无评论...
验证码 换一张
取 消