5280_Lifestyle (12/17/2012)
My brain isn't working right now. I have data such as 'HEYE-B Euro-IPA 69793' and 'HEYE-B RFE-IPA 70940'. I need to retrieve the middle value, such as 'Euro-IPA' or 'RFE-IPA'. How would that be coded to retrieve those values?
Forcing my brain to work resulted in the following. It's the best that I could manage. Seems to have done the trick.
CASE WHEN (CHARINDEX(' ',ColName)=0)
THEN 'Unknown'
ELSE SUBSTRING(ColName,CHARINDEX(' ',ColName)+1,
LEN(ColName) -
LEN(LEFT(ColName, CHARINDEX(' ',ColName))) -
LEN(RIGHT(ColName, CHARINDEX(' ',ColName) - 1)))
END AS [Middle_Value]
"Nicholas"