August 2, 2022 at 8:59 pm
I am trying to standardize an address field. I want to extract the first three words of the full address (ex: 123 Main Street) into a new column. I am using the code below, which is not working. Any insight would be appreciated. Thank you!
set [FIRST_THREE_WORDS] = SUBSTRING(ADDRESS, 0, CHARINDEX(' ', ADDRESS, CHARINDEX(' ', ADDRESS, CHARINDEX(' ', ADDRESS, 0)+1)+1)) FIRST_THREE_WORDS
FROM [ADDRESSES]
August 2, 2022 at 9:08 pm
SELECT [FIRST_THREE_WORDS] = LEFT(ADDRESS + ' ', CHARINDEX(' ', ADDRESS + ' ', CHARINDEX(' ', ADDRESS, CHARINDEX(' ', ADDRESS + ' ', 0)+1)+1))
FROM ( SELECT '123 Main Street' ) AS [ADDRESSES](Address)
SQL DBA,SQL Server MVP(07, 08, 09) "It's a dog-eat-dog world, and I'm wearing Milk-Bone underwear." "Norm", on "Cheers". Also from "Cheers", from "Carla": "You need to know 3 things about Tortelli men: Tortelli men draw women like flies; Tortelli men treat women like flies; Tortelli men's brains are in their flies".
August 2, 2022 at 9:26 pm
I am trying to standardize an address field. I want to extract the first three words of the full address (ex: 123 Main Street) into a new column. I am using the code below, which is not working. Any insight would be appreciated. Thank you!
set [FIRST_THREE_WORDS] = SUBSTRING(ADDRESS, 0, CHARINDEX(' ', ADDRESS, CHARINDEX(' ', ADDRESS, CHARINDEX(' ', ADDRESS, 0)+1)+1)) FIRST_THREE_WORDS FROM [ADDRESSES]
That's going to lead to your own personal bit of hell. Consider addresses like the following.
123 South East New London Road
18232 E. via Rimini Rd
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 3 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy