declare @t table (col varchar(20))insert @t select
'000000123'
union all select
'000145'
union all select
'01'
union all select
'00000048'
union all select
'0001556'
union all select --加条不以0开头的
'124'select stuff(col,1,PATINDEX ( '%[^0]%' , col )-1 ,'') as col
from @t--结果
col
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
123
145
1
48
1556
124(所影响的行数为 6 行)
'000000123'
union all select
'000145'
union all select
'01'
union all select
'00000048'
union all select
'0001556'
union all select --加条不以0开头的
'124'select stuff(col,1,PATINDEX ( '%[^0]%' , col )-1 ,'') as col
from @t--结果
col
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
123
145
1
48
1556
124(所影响的行数为 6 行)
我想避免
SELECT CONVERT(INT,col) from 表名
--这把字符转成数字再转回字符