How to split a string after specific character in SQL Server and update this value to specific column

前端 未结 8 1146
死守一世寂寞
死守一世寂寞 2020-12-01 09:59

I have table with data 1/1 to 1/20 in one column. I want the value 1 to 20 i.e value after \'/\'(front slash) is updated into other column in same

相关标签:
8条回答
  • 2020-12-01 10:57

    Maybe something like this:

    First some test data:

    DECLARE @tbl TABLE(Column1 VARCHAR(100))
    
    INSERT INTO @tbl
    SELECT '1/1' UNION ALL
    SELECT '1/20' UNION ALL
    SELECT '1/2'
    

    Then like this:

    SELECT
        SUBSTRING(tbl.Column1,CHARINDEX('/',tbl.Column1)+1,LEN(tbl.Column1))
    FROM
        @tbl AS tbl
    
    0 讨论(0)
  • 2020-12-01 10:57
    SELECT SUBSTRING(ParentBGBU,0,CHARINDEX('-',ParentBGBU,0)) FROM dbo.tblHCMMaster;
    
    0 讨论(0)
提交回复
热议问题