开发者

MS access update query to update part of string

开发者 https://www.devze.com 2022-12-09 19:36 出处:网络
I am开发者_JS百科 trying to use an update query to update the first 3 characters of a string. but i am getting a syntax error

I am开发者_JS百科 trying to use an update query to update the first 3 characters of a string. but i am getting a syntax error

my query is

update table1, table 2 set left(table1.stringfield, 3) = table2.stringfield

thankstksy


OK, there's a couple of things

Firstly, your set statement should look something like this

set table1.stringfield = Left(table2.stringfield, 3) _
                            + mid$(table1.stringfield, 4)

This will take the first 3 chars from table2.stringfield, and the chars from 4 onwards in table1.stringfield.

This will run into problems if table1.stringfield is less than 4 characters long, you might want something like

set table1.stringfield = Left(table2.stringfield, 3) + 
iif(len(table1.stringfield) > 3, mid$(table1.stringfield, 4), "")

Secondly, you need to join the two tables together, I don't have MSAccess handy at the moment, the easiest way to do this is to put a straight forward update query together with the designer, and then look at the SQL view for that query.

Hope this helps :)

0

精彩评论

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