r/learnSQL • • Apr 04 '26

Column Separation Question

Hi all! Thanks for your help so far learning SQL! Another quick question ...

I'm trying to separate a text column at spaces. My table is titled Cities and has 3 rows with a column name City. The 3 rows are Los Angeles, Ottawa and San Francisco. I want SQL to separate the column into separate columns at the space.

I wrote SELECT SUBSTRING(Cities, CHARINDEX(' ', Cities) +1, LEN(Cities)) FROM Cities, but it is just returning Angeles, Ottawa and Francisco.

What code would output 2 columns with the first column being Los, Ottawa and San and the second column being Angeles, blank, Francisco?

3 Upvotes

6 comments sorted by

View all comments

Show parent comment

1

u/jfrazierjr Apr 04 '26

What this guy's says. You also miss out on edge cases like say new York city. Tons of others when you get in 5 or y name parts on spanish locales.