找到你要的答案

Q:Proper form of a regex in SELECT of an Access ComboBox

Q:一个访问组合在一个正则表达式选择适当的形式

I have a ComboBox which takes it's source from a query. One of the query' fields is a number like H-1234=AAA-0382 or HN903=BBB-94522 (Field is ID Symix, Table is DessinSelonProjet_Choix).

In the combobox, I want to display this number, but not the part before the = sign in both cases. I wanted to use a Mid(number, position of = sign). In SQL I researched that the position function is CHARINDEX, but I did not manage to get it working. Here is the code when showing the whole thing:

SELECT DessinSelonProjet_Choix.[ID Symix], DessinSelonProjet_Choix.[Numéro Document], 
DessinSelonProjet_Choix.Description, DessinSelonProjet_Choix.[Groupe Source]
FROM DessinSelonProjet_Choix
ORDER BY DessinSelonProjet_Choix.[ID Symix];

Here is what I tried:

SELECT Mid(DessinSelonProjet_Choix.[ID Symix],CHARINDEX('=', 
DessinSelonProjet_Choix.[ID Symix]) AS [Location]) AS Expr1, 
DessinSelonProjet_Choix.[Numéro Document], 
DessinSelonProjet_Choix.Description, DessinSelonProjet_Choix.[Groupe Source]
FROM DessinSelonProjet_Choix
ORDER BY DessinSelonProjet_Choix.[ID Symix];

Syntax error (missing operator) in the expression Mid(DessinSelonProjet_Choix.[ID Symix],CHARINDEX('=', DessinSelonProjet_Choix.[ID Symix]) AS [Location]) AS Expr1

我有一个组合框以来自查询的源。一个查询的字段是一个数字像h-1234 = aaa-0382或hn903 = bbb-94522(字段ID赛美克斯,表dessinselonprojet_choix)。

In the combobox, I want to display this number, but not the part before the = sign in both cases. I wanted to use a Mid(number, position of = sign). In SQL I researched that the position function is CHARINDEX, but I did not manage to get it working. Here is the code when showing the whole thing:

SELECT DessinSelonProjet_Choix.[ID Symix], DessinSelonProjet_Choix.[Numéro Document], 
DessinSelonProjet_Choix.Description, DessinSelonProjet_Choix.[Groupe Source]
FROM DessinSelonProjet_Choix
ORDER BY DessinSelonProjet_Choix.[ID Symix];

这里是我尝试:

SELECT Mid(DessinSelonProjet_Choix.[ID Symix],CHARINDEX('=', 
DessinSelonProjet_Choix.[ID Symix]) AS [Location]) AS Expr1, 
DessinSelonProjet_Choix.[Numéro Document], 
DessinSelonProjet_Choix.Description, DessinSelonProjet_Choix.[Groupe Source]
FROM DessinSelonProjet_Choix
ORDER BY DessinSelonProjet_Choix.[ID Symix];

语法错误(缺少操作符)在表达中(dessinselonprojet_choix。[ ID赛美克斯],charindex(“=”,dessinselonprojet_choix。[ ID赛美克斯])为[地点])作为表达式

answer1: 回答1:
SELECT 
Mid([ID Symix], INSTR('=', [ID Symix])+1, len([ID Symix])-INSTR('=', [ID Symix])) AS Expr1,
[Numéro Document],   
Description, 
[Groupe Source]
FROM DessinSelonProjet_Choix
ORDER BY [ID Symix];

The statement you had was using an alias within a function. Also, you have to use len to get all characters after = in your string.

SELECT 
Mid([ID Symix], INSTR('=', [ID Symix])+1, len([ID Symix])-INSTR('=', [ID Symix])) AS Expr1,
[Numéro Document],   
Description, 
[Groupe Source]
FROM DessinSelonProjet_Choix
ORDER BY [ID Symix];

您所使用的语句是在函数内使用别名。同时,你必须使用Len之后你得到的所有字符的字符串。

sql  regex  ms-access