Skip to content
Advertisement

SQL concatenate columns into string and only pull address

I have 4 fields that are address fields, but the address fields can be blank and have a persons name within one of the 4 fields. The name is usually before the start of the address. What I need to do is remove and names and empty string and only pull the core address or column that starts with a number.

For Example:

Results: enter image description here

What I need to see is the core address only in a single string Like this..

Advertisement

Answer

I took this a little different direction.

First I concatenated the 4 sourceaddr fields together in one temp table like this.

Next I created another temp table and brought the concatenated field in and removed all alpha characters like this.

By using the STUFF function and the above logic I was able to get just the core address all concatenated together like this. This logic removes any of the field that were empty strings and only looks for the first number in the string.

RESULTS:

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement