How can I add a character into a specified position into string in SQL SERVER?

前端 未结 9 2344
傲寒
傲寒 2021-02-19 07:48

I have a varchar field like:

195500
122222200

I need to change these values to:

1955.00
1222222.00
9条回答
  •  误落风尘
    2021-02-19 08:22

    CREATE TABLE #T ( Value VARCHAR(20) )
    INSERT INTO #T ( Value ) VALUES ( 195500 ), ( 122222200)
    
    SELECT 
        Value
    ,   NewValue = CONVERT(DECIMAL(17,2),CONVERT(DECIMAL,Value) / 100)
    FROM #T
    
    |     Value |   NewValue |
    |-----------|------------|
    |    195500 |    1955.00 |
    | 122222200 | 1222222.00 |
    

提交回复
热议问题