Using LastIndexOf and SubString in mssql

22,204
SELECT Id,
       RIGHT(Code, CHARINDEX('.', REVERSE('.' + Code)) - 1) AS [Result],
       Code
FROM   YourTable 
Share:
22,204
onuralp
Author by

onuralp

@onuralptaner

Updated on July 09, 2022

Comments

  • onuralp
    onuralp almost 2 years

    How do I get [Result] column from [Code] column using ms sql

    Id          Code
    200001      43791
    200001      67036
    200006      19.09.01.08683      
    200006      03.01.04.01.64230   
    200007      19.01.03.02804    
    
    Id          Result  Code
    200001      43791   43791
    200001      67036   67036
    200006      08683   19.09.01.08683      
    200006      64230   03.01.04.01.64230   
    200007      02804   19.01.03.02804    
    
  • onuralp
    onuralp over 11 years
    Working perfectly. Thank You