代码之家  ›  专栏  ›  技术社区  ›  CoderDennis

在MS Access SQL中是否有等效的子字符串函数?

  •  22
  • CoderDennis  · 技术社区  · 16 年前

    我想在MS Access查询中执行类似的操作,但子字符串是未定义的函数。

    SELECT DISTINCT SUBSTRING(LastName, 1, 1)
    FROM Authors;
    
    4 回复  |  直到 10 年前
        1
  •  29
  •   Tomalak    16 年前

    您可以使用vba字符串函数(如@oneday注释中指出的那样,它们实际上不是vba函数,而是来自ms-jet库的等价函数)。就函数签名而言,即使实际 存在 不需要MS访问,它们就可以使用。):

    SELECT DISTINCT Left(LastName, 1)
    FROM Authors;
    
    SELECT DISTINCT Mid(LastName, 1, 1)
    FROM Authors;
    
        2
  •  6
  •   l0pan    10 年前

    我认为在access中有mid()和left()和right()。

        3
  •  3
  •   webzy    10 年前

    我与MSAccess VBA一起工作过。 我想你在找中等功能的

    例子

        dim myReturn as string
        myreturn = mid("bonjour tout le monde",9,4)
    

    会把“吹捧”的价值还给你

        4
  •  2
  •   Furqan Safdar    12 年前

    我找不到添加此功能的现成模块,因此我编写了一个:

    在Access中,转到“数据库工具”功能区的“宏”区域中,单击“进入Visual Basic”。在左上角的项目区域中,右键单击文件名,然后选择“插入”->模块。在模块中粘贴:

    Public Function Substring_Index(strWord As String, strDelim As String, intCount As Integer) As String
    
    Substring_Index = delims
    
    start = 0
    test = ""
    
    For i = 1 To intCount
        oldstart = start + 1
        start = InStr(oldstart, strWord, strDelim)
        Substring_Index = Mid(strWord, oldstart, start - oldstart)
    Next i
    
    End Function
    

    将模块另存为模块1(默认)。现在可以使用如下语句:

    SELECT Substring_Index([fieldname],",",2) FROM table