I am trying to extract the numbers out of the strings below in SQL Server. I have looked at other questions but am struggling to find a solution that will capture the numbers regardless of space indexes. My challenge is extracting these numbers when the number of spaces until the number is not static.
The numbers are always before the last instance of space and before the K.
Item Name
----------------------
AA BB CCC DDDD E 1.5 K
CC EEE-EEE 0.5 K
CC EEEEEEE 7 K
CC DD EEE-EEE 0.5 K
DDDD EEE 5 K
DDDD EEE EEE 0.5 K
I have tried without luck among other variations:
SELECT LEFT(ITEMNAME, CHARINDEX(' ', ITEMNAME)),
LEFT(ITEMNAME, PATINDEX('%[^0-9]%', ITEMNAME)) as [Item Name]
My desired output would be:
Item Name
---------
1.5
0.5
7
0.5
5
0.5
Any ideas on how to extract this? Thanks!
K?' K'? (white space + K)