I’m trying to trim some info from a table. The column has a number and then a word (e.g. 5 Apples). I just need the number so that I can sum the total of apples. I can’t use count because I need to go by the value (e.g. 5 Apples for one, 3 Apples for the other) and count will just return that there are 2 entries and not pull the 5 and 3.
I’ve tried using SUM but it doesn’t work either.
Can anyone help (Or point me to a tutorial) that will explain how I can trim/extract info from the columns value? I’ve been looking and have only been able to find how to trim spaces (Which would be nice if I could trim everything after spaces too, then I’d just be able to trim away after the number)
A combination of sum, cast, substring, charindex will do the work i think:
Find the first occurence of whitespace, take the substring of the column until the first whitespace position, cast it as an integer and sum it up.
Edit: first char is 1 in substring