简体   繁体   English

如何通过在两者之间插入字符来更新字符串

[英]How to update a string by inserting characters in between

In MS-Access, I have a text field labeled idStr and currently, the data shows like this "000000000". 在MS-Access中,我有一个标记为idStr的文本字段,当前,数据显示为“ 000000000”。 I would like to transform the string by writing an update query and making it like this: "000-00-0000". 我想通过编写一个更新查询并使它像这样:“ 000-00-0000”来变换字符串。 In other words, I'd like to insert - (hyphen) after the third character and after the fifth character. 换句话说,我想在第三个字符之后和第五个字符之后插入-(连字符)。

The only solution I've seen is to write a select query using left and right but I'm actually attempting to update the string and make it permanent 我见过的唯一解决方案是使用向左和向右编写选择查询,但是我实际上是在尝试更新字符串并将其永久化

If you want to change the string, you can put the logic in a update statement: 如果要更改字符串,可以将逻辑放在update语句中:

update t
    set idstr = left(idstr, 3) & "-" & mid(idstr, 4, 2) & "-" & right(idstr, 4);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM