求助:一个函数。提取字段中最后出现一个“数字”。

请填写用户昵称 2011-04-02 03:15:07
求助:一个函数。提取字段中最后出现一个“数字”。
比如:ABCD01 就是1
b00212 就是2
1213ABc 就是3
...全文
138 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
zxjnew 2011-04-02
  • 打赏
  • 举报
回复
substring(reverse(col),patindex('%[0-9]%',reverse(col)),1)

是亮点
yy413493 2011-04-02
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 luoyoumou 的回复:]

引用 2 楼 jiangshun 的回复:
select
result=substring(reverse(col),patindex('%[0-9]%',reverse(col)),1)
from [TB]

[/Quote]
对的!
nevergu 2011-04-02
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 jiangshun 的回复:]
SQL code
--> 测试数据: [TB]
if object_id('[TB]') is not null drop table [TB]
create table [TB] (col varchar(7))
insert into [TB]
select 'ABCD01' union all
select 'b00212' union all
select '1213ABc'……
[/Quote]

+1
luoyoumou 2011-04-02
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 jiangshun 的回复:]

SQL code
--> 测试数据: [TB]
if object_id('[TB]') is not null drop table [TB]
create table [TB] (col varchar(7))
insert into [TB]
select 'ABCD01' union all
select 'b00212' union all
select '1213ABc'

sel……
[/Quote]

顶!
AcHerat 2011-04-02
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 jiangshun 的回复:]

SQL code
--> 测试数据: [TB]
if object_id('[TB]') is not null drop table [TB]
create table [TB] (col varchar(7))
insert into [TB]
select 'ABCD01' union all
select 'b00212' union all
select '1213ABc'

sel……
[/Quote]

+++++++++++就这个。
jiangshun 2011-04-02
  • 打赏
  • 举报
回复
--> 测试数据: [TB]
if object_id('[TB]') is not null drop table [TB]
create table [TB] (col varchar(7))
insert into [TB]
select 'ABCD01' union all
select 'b00212' union all
select '1213ABc'

select
result=substring(reverse(col),patindex('%[0-9]%',reverse(col)),1)
from [TB]
/*

result
------
1
2
3

(3 行受影响)

*/

drop table tb
快溜 2011-04-02
  • 打赏
  • 举报
回复
select right(字段,1) from tb

22,209

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧