Home Forums SQL Server 7,2000 T-SQL Trimming Last 3 Numbers from some Records RE: Trimming Last 3 Numbers from some Records

  • Hi,

    I think below one will be the easiest way to query your data

    SELECT <Col_Name>,CASE WHEN PATINDEX('%[0-9]%',REVERSE(<Col_Name>))>0

    THEN RTRIM(SUBSTRING(<Col_Name>,1,LEN(<Col_Name>)-(PATINDEX('%[0-9]%',REVERSE(<Col_Name>)))-2)) -- Please note, we have considered 3 numeric digits in this case

    ELSE RTRIM(<Col_Name>) END AS New_String from <table>