我有一个varchar字段,如:
195500
122222200
Run Code Online (Sandbox Code Playgroud)
我需要将这些值更改为:
1955.00
1222222.00
Run Code Online (Sandbox Code Playgroud)
vha*_*lgi 16
try this
Declare @s varchar(50) = '1234567812333445'
Select Stuff(@s, Len(@s)-1, 0, '.')
--> 12345678123334.45
Run Code Online (Sandbox Code Playgroud)
Jus*_*tin 10
查询:
SELECT col,
LEFT(col,len(col)-2) + '.' + RIGHT(col,2) as newcol
FROM Table1
Run Code Online (Sandbox Code Playgroud)
结果:
| COL | NEWCOL |
|-----------|------------|
| 195500 | 1955.00 |
| 122222200 | 1222222.00 |
Run Code Online (Sandbox Code Playgroud)
如果你想添加一个'.' 在您的值的最后两位数字之前,您可以执行以下操作:
SELECT substring(code,0,len(code)-1)+'.'+substring(code,len(code)-1,len(code))
FROM table1;
Run Code Online (Sandbox Code Playgroud)