Database
Reverse Substring
This query searches from right > left to find the first space then inserts a "-" in there
UPDATE action
SET action_disp =
SUBSTRING(Action_Disp, 0, len (Action_disp) - CHARINDEX(' ', Reverse(action_Disp), 5)+1 )
+ ' -' + RIGHT(action_Disp, CHARINDEX(' ', Reverse(action_Disp), 5)-1)
SET action_disp =
SUBSTRING(Action_Disp, 0, len (Action_disp) - CHARINDEX(' ', Reverse(action_Disp), 5)+1 )
+ ' -' + RIGHT(action_Disp, CHARINDEX(' ', Reverse(action_Disp), 5)-1)
This one does the same but removes any "-" chars from the string before inserting the -
UPDATE action
SET action_disp =
SUBSTRING(Action_Disp, 0, len (Action_disp) - CHARINDEX(' ', Reverse(action_Disp), 5)+1 )
+ ' -' + REPLACE(RIGHT(action_Disp, CHARINDEX(' ', Reverse(action_Disp), 5)-1), '-', '')
SET action_disp =
SUBSTRING(Action_Disp, 0, len (Action_disp) - CHARINDEX(' ', Reverse(action_Disp), 5)+1 )
+ ' -' + REPLACE(RIGHT(action_Disp, CHARINDEX(' ', Reverse(action_Disp), 5)-1), '-', '')