sql create a field from a field

前端 未结 4 922
旧时难觅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:15

    Based on this question and your duplicate question, I understand your table has a field which includes both the street address and email address and you want to split those into separate fields.

    So your table includes this ...

    YourField
    ------------------------------
    1234 ave willie haha@yahoo.com
    123 avenue bb@yahoo.com
    

    And you want this ...

    YourField                       street_address  email_address
    ------------------------------  --------------- --------------
    1234 ave willie haha@yahoo.com  1234 ave willie haha@yahoo.com
    123 avenue bb@yahoo.com         123 avenue      bb@yahoo.com
    

    If that is correct, you can use the InstrRev() function to determine the position of the last space in YourField. Everything before the last space is the street address; everything after is the email address.

    SELECT
        y.YourField,
        Left(y.YourField, InstrRev(y.YourField, ' ') -1) AS street_address,
        Mid(y.YourField, InstrRev(y.YourField, ' ') +1) AS email_address
    FROM YourTable AS y;
    

    You may need to add a WHERE clause to ensure the query only tries to evaluate rows which include your expected YourField value patterns.

提交回复
热议问题