sql create a field from a field

前端 未结 4 924
旧时难觅i
旧时难觅i 2021-01-23 18:48

I need to run a query that would pull information from a field that has 2 types of data .

Field is address and has 123 avenue as data and bb@yahoo.com.

I need to

4条回答
  •  [愿得一人]
    2021-01-23 19:19

    If you have a street address and then an email address in the same field, and want to split them, then use this.
    We'll call your original field Addy, and the new fields Street & Email.

    SELECT Left(Addy, InStrRev(Addy, " ", InStr(Addy, "@")) - 1) AS Street, mid(Addy, InStrRev(Addy, " ", InStr(Addy, "@")) + 1) AS Email.
    

    What this does is look for the @, then go backwards and look for the first space. The first function takes every left of that space and calls it Street, while the second function takes everything to the right.

    The function is really 3 functions nested together. To really understand what it's doing, I'll dissect it.

    I = InStr(Addy, "@")
    J = InStrRev(Addy, " ", I)
    Street = Left(Addy,J-1)
    

提交回复
热议问题