I have a varchar field that contains a string with the following:
"The Scenario is BUDGET; the Year is 2018; the period is June"
The values of Scenario
, Year
and Period
may vary.
I am building a script, and part of what is needed is to get the last word before each semicolon (in this case BUDGET
and 2018
, but could be other words) and the last word (in this case the month).
I have done several tests and the most I have achieved is the following:
select SUBSTRING(strDescription, CHARINDEX('The Scenario is',
strDescription,+16), CHARINDEX(';',strDescription,-1)) as Scenario,
,SUBSTRING(strDescription, CHARINDEX('The Year is', strDescription),
CHARINDEX(';',strDescription,1)) as Year
,SUBSTRING(strDescription, CHARINDEX('The Start Period is', strDescription),
CHARINDEX(';',strDescription,-1)) as Period
from TECHBUD_TASK_AUDIT;
Resultado:
---------------------- ---------------------- ----------------------
The Scenario is BUDGET the Year is 2018; the S the Start Period is Jun
Resultado esperado:
-------- -------- -------
BUDGET 2018 June
Try several suggestions from you, such as REVERSE and LEFT, but I can not make the correct syntax. Is there any way to achieve the sentence without the use of variables?
Thanks! Kyana