I have a text like below
AB-MFG 49UN STEEL
GH-NH, 345UN IRON
M787 UH, 77 UNITS GREY
G7-YUT 365 UNITS WHITE
and i want to extract the numbers before string UN and UNITS
+------------------------+-----+
| AB-MFG 49UN STEEL | 49 |
+------------------------+-----+
| GH-NH, 345UN IRON | 345 |
+------------------------+-----+
| M787 UH, 77 UNITS GREY | 77 |
+------------------------+-----+
| G7-YUT 365 UNITS WHITE | 365 |
+------------------------+-----+
Currently I'm using belong query. I have to write a case statement to cover both cases. Are there any alternate efficient solution for this?
SELECT REVERSE(SUBSTRING(SUBSTRING(REVERSE(LEFT(desc, CHARINDEX('UN ', desc))), 2, 1000), 1, CHARINDEX(' ', SUBSTRING(REVERSE(LEFT(desc, CHARINDEX('UN ', desc))), 2, 1000))))
FROM MYTABLE