select reverse(substring(reverse(v),patindex('%[1-9]%',reverse(v)),len(v)))
from
(
select '1000000000000000000' as v union all
select '1010000000000000000' as v union all
select '1010100000000000000' as v union all
select '1010101000000000000'
)v
方法二(不受限制,通用):
declare @str varchar(255),@len int
set @str='1020030000'
set @len=len(@str)
select @len
begin
if substring(@str,@len,1) ='0'
set @len=@len-1
else
break
end
select left(@str,@len)
#3
reverse(convert(bigint,reverse(v)))
这两个哪个好?
#4
select REVERSE(CAST(REVERSE(v) AS BIGINT))
from
(
select '1000000000000000000' as v union all
select '1010000000000000000' as v union all
select '1010100000000000000' as v union all
select '1010101000000000000'
)v
/*
1
101
10101
1010101
*/
#5
everse(convert(bigint,reverse(v)))用就这个吧
#6
试试这个:
select reverse(substring(reverse(v),patindex('%[1-9]%',reverse(v)),len(v)))
from
(
select '1000000000000000000' as v union all
select '1010000000000000000' as v union all
select '1010100000000000000' as v union all
select '1010101000000000000'
)v
reverse(convert(bigint,reverse(v)))
这两个哪个好?
建议使用 1# ,如果长度发生了变化,也没什么影响;
#7
试试这个:
select reverse(substring(reverse(v),patindex('%[1-9]%',reverse(v)),len(v)))
from
(
select '1000000000000000000' as v union all
select '1010000000000000000' as v union all
select '1010100000000000000' as v union all
select '1010101000000000000'
)v
select reverse(convert(nvarchar(50),convert(int,reverse(v)))) from
(select '1000000000000000000' as v union all
select '1010000000000000000' as v union all
select '1010100000000000000' as v union all
select '1010101000000000000') a
--先反转,转类型,再反转就可以了.这样应该效率会高一些.
#10
#9类型INT长度是不够,尾数为1时直接报错
100000000000000000
1
#1
试试这个:
select reverse(substring(reverse(v),patindex('%[1-9]%',reverse(v)),len(v)))
from
(
select '1000000000000000000' as v union all
select '1010000000000000000' as v union all
select '1010100000000000000' as v union all
select '1010101000000000000'
)v
方法二(不受限制,通用):
declare @str varchar(255),@len int
set @str='1020030000'
set @len=len(@str)
select @len
begin
if substring(@str,@len,1) ='0'
set @len=@len-1
else
break
end
select left(@str,@len)
#3
试试这个:
select reverse(substring(reverse(v),patindex('%[1-9]%',reverse(v)),len(v)))
from
(
select '1000000000000000000' as v union all
select '1010000000000000000' as v union all
select '1010100000000000000' as v union all
select '1010101000000000000'
)v
reverse(convert(bigint,reverse(v)))
这两个哪个好?
#4
select REVERSE(CAST(REVERSE(v) AS BIGINT))
from
(
select '1000000000000000000' as v union all
select '1010000000000000000' as v union all
select '1010100000000000000' as v union all
select '1010101000000000000'
)v
/*
1
101
10101
1010101
*/
#5
试试这个:
select reverse(substring(reverse(v),patindex('%[1-9]%',reverse(v)),len(v)))
from
(
select '1000000000000000000' as v union all
select '1010000000000000000' as v union all
select '1010100000000000000' as v union all
select '1010101000000000000'
)v
reverse(convert(bigint,reverse(v)))
这两个哪个好?
everse(convert(bigint,reverse(v)))用就这个吧
#6
试试这个:
select reverse(substring(reverse(v),patindex('%[1-9]%',reverse(v)),len(v)))
from
(
select '1000000000000000000' as v union all
select '1010000000000000000' as v union all
select '1010100000000000000' as v union all
select '1010101000000000000'
)v
reverse(convert(bigint,reverse(v)))
这两个哪个好?
建议使用 1# ,如果长度发生了变化,也没什么影响;
#7
试试这个:
select reverse(substring(reverse(v),patindex('%[1-9]%',reverse(v)),len(v)))
from
(
select '1000000000000000000' as v union all
select '1010000000000000000' as v union all
select '1010100000000000000' as v union all
select '1010101000000000000'
)v
select reverse(convert(nvarchar(50),convert(int,reverse(v)))) from
(select '1000000000000000000' as v union all
select '1010000000000000000' as v union all
select '1010100000000000000' as v union all
select '1010101000000000000') a