I have a table called catalog with the following columns, and I want to find the last occurence of the - in CategoryDescription2 and remove any text preceding it. For example, I want CategoryDescription2 to just have MINOR DEPARTMENT DRY GROCERY instead of MAJOR DEPARTMENT GROCERY-MINOR DEPARTMENT DRY GROCERY. CategoryDescription1 CategoryDescription2 MAJOR DEPARTMENT MAJOR DEPARTMENT GROCERY-MINOR DEPARTMENT DRY GROCERY
Something like this would work: DECLARE @string VARCHAR(100) = 'MAJOR DEPARTMENT GROCERY-MINOR DEPARTMENT DRY GROCERY' SELECT REVERSE(LEFT(REVERSE(@string),CHARINDEX('-',REVERSE(@string),1)-1)) Result: MINOR DEPARTMENT DRY GROCERY You would just use that code in an UPDATE statement to adjust the values accordingly. Hope that helps!