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

  • Guitar_player (9/1/2014)


    Eirikur Eiriksson (9/1/2014)


    Here is another method, find the last character which is not space or numeric

    😎

    Hi Eiriksson,

    There are also quite records like 'ABC DEF 210 ' , 'ggh / sah ggh 590'...

    So does the logic applies for these too ?

    If possible can i get any function directly for these ..to check if the last digits are numbers ..if they are numbers then delete them and also the sapce and if not Trim the last space

    Thanks & Regards,

    Guitar Player

    That should be no problem, the code trims the string to the last Alpha character in the string

    This set

    (1,'ABCD 123')

    ,(2,'XY 567')

    ,(3,'ghj 001')

    ,(4,'RUT')

    ,(5,'PUT')

    ,(6,'ABC DEF 210')

    ,(7,'ggh / sah ggh 590')

    ,(7,'ABC 123 DEF 456')

    becomes this

    ID CLEAN_COL

    ----------- -----------------

    1 ABCD

    2 XY

    3 ghj

    4 RUT

    5 PUT

    6 ABC DEF

    7 ggh / sah ggh

    7 ABC 123 DEF