Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7050063
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:05:51+00:00 2026-05-28T03:05:51+00:00

I have an address column that contains address, state and postcode. I would like

  • 0

I have an address column that contains address, state and postcode. I would like to extract the address, suburb, state, and postcode into separate columns, how can a do this as the length of the address is variable, there is a ^ to separate the address and “other” details. The State can be 2 or 3 characters long and the postcode is always 4 characters long.

PostalAddress                            TO BE  Address   Suburb       State  Postcode
28 Smith Avenue^MOOROOLBARK VIC 3138^    28 Smith Avenue  MOOROOLBARK  VIC    3138
16 Farr Street^HEYFIELD VIC 3858^        16 Farr Street   HEYFIELD     VIC    3858
17 Terry Road^LOWER PLENTY VIC 3093^     17 Terry Road    LOWER PLENTY VIC    3093  
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T03:05:52+00:00Added an answer on May 28, 2026 at 3:05 am

    String parsing in SQL is messy and tends to be brittle. I usually think it’s best to do these sort of tasks outside of SQL altogether. That said, given the mini-spec above, it is possible to parse the data into the fields you want like so:

    select 
      left(PostalAddress, charindex('^', PostalAddress) - 1) as street_address,
      left(second_part, len(second_part) - charindex(' ', reverse(second_part))) as suburb,
      right(second_part, charindex(' ', reverse(second_part))) as state,
      reverse(substring(reverse(PostalAddress), 2, 4)) as postal_code
    from (
      select
        PostalAddress,
        rtrim(reverse(substring(reverse(PostalAddress), 6, len(PostalAddress) - charindex('^', PostalAddress) - 5))) as second_part
      from Addresses
    ) as t1
    

    Note that you’ll need so substitute your table name for what I’ve called addresses in the subquery above.

    You can see this in action against your sample data here.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a column that contains address line 2 type values. this column can
I have table which contains columns like SiteID (identity_Col) SiteName POrderID Location Address Cluster
A column in my table contains email addresses. I have a text string that
In my SQL 2008 database table, I have one column name AUTHOR that contains
I have a table that has 5 columns: AcctId (int), Address1 (varchar), Address2 (varchar),
EDIT: I have added Slug column to address performance issues on specific record selection.
I have an address finder system whereby a user enters a postcode, if postcode
I have a database with Points of Interest that all have an address. I
I have a listbox that has a datatemplate which contains multiple text boxes. I
I have two tables data1 and data2. Data1 contains contains 2 columns, emailaddress and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.