www.webdeveloper.com
Results 1 to 3 of 3

Thread: asp+access SUBSTRING_INDEX

  1. #1
    Join Date
    Jan 2003
    Location
    Israel
    Posts
    1,381

    asp+access SUBSTRING_INDEX

    in mysql there is
    which means :
    SUBSTRING_INDEX(str,delim,count)

    Returns the substring from string str before count occurrences of the delimiter delim. If count is positive, everything to the left of the final delimiter (counting from the left) is returned. If count is negative, everything to the right of the final delimiter (counting from the right) is returned.
    mysql> SELECT SUBSTRING_INDEX('www.mysql.com', '.', 2);
    -> 'www.mysql'
    mysql> SELECT SUBSTRING_INDEX('www.mysql.com', '.', -2);
    -> 'mysql.com'
    is there something like this in a query to access?

  2. #2
    Join Date
    Jan 2004
    Location
    Melbourne, Australia
    Posts
    5,298
    I dont think MS Access supports that function. VBScript does, though.

  3. #3
    Join Date
    Oct 2012
    Posts
    1
    I couldn't find an off-the-shelf module that added this function, so I wrote one:

    In Access, go to the Database Tools ribbon, in the Macro area click into Visual Basic. In the top left Project area, right click the name of your file and select Insert -> Module. In the module paste this:

    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

    Save the module as module1 (the default). You can now use statements like:

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

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles