In a particular column, I am trying to extract everything before any whitespace. For example in the string "text1 text2"
there are three spaces between "text1" and "text2", and I just want text 1.
But within this same column there could be a string like "text1 text2"
, and here there are 5 spaces in between text1 and text2.
I tried the following code:
SELECT LEFT(column, CHARINDEX(' ', column) -1 )
But as I quickly learned, this would only work on strings where there is only one space in between the two words.
Any idea on how I can index for whenever any whitespace appears in a string?