Home Forums SQL Server 2008 SQL Server Newbies Parsing data to from a field into a new record of a different table RE: Parsing data to from a field into a new record of a different table

  • Jeff and anyone else looking, I found some VBA code and did this inside of Excel that was link to my DB.

    I know that this will make the DBA's cringe a little 😉

    Create a VBA function

    Function StrSplit(InString, Pos, Delim)

    StrArray = Split(InString, Delim)

    StrSplit = StrArray(Pos - 1)

    End Function

    Use

    To get the 3rd field from a coma delimited string:

    =StrSplit(A1,3,",")

    To get the 2nd field from a space delimited string:

    =StrSplit(A1,2," ")

    Nested example:

    To get the 2nd field of a space delimited string nested inside a cama delimed string. Example to get "Doe" out of the following string.

    A1=Electrician, John Doe,1234 main st., any town, USA

    =StrSplit(TRIM(StrSplit(A3,2,",")),2," ")

    NOTE: I know this is an old post, but for anyone else who may have an need. Don't over complicate things, use the KISS method like this.