我的代码如下所示,它几乎是完美的,但它有一个小缺陷。
SELECT instr (1, "n123456 (name lastname)", "(")+1 AS [First Char],
instr (1, "n123456 (name lastname)", ")")-1 AS [Last Char],
mid("n123456 (name lastname)", instr (1, "n123456 (name lastname)",
"(")+1,instr (1, "n123456 (name lastname)", ")")) AS [text];
因此它返回以下值:
- [First Char] = 10
- [Last Char] = 22
- [text] =姓氏姓氏)
我无法弄清楚如何从字符串中删除最后一个括号。有什么想法吗?
答案 0 :(得分:0)
mid函数语法是
Mid ( text, start_position, number_of_characters )
您指定的字符数是错误的。它应该是你的([LastChar]-1) - [First Char]
尝试以下代码
SELECT instr (1, "n123456 (name lastname)", "(")+1 AS [First Char],
instr (1, "n123456 (name lastname)", ")")-1 AS [Last Char],
mid("n123456 (name lastname)", instr (1, "n123456 (name lastname)", "(")+1,
instr (1, "n123456 (name lastname)", ")")-2 -
instr (1, "n123456 (name lastname)", "(")+1) AS [text];
o / p是