SqlServer如何取出字符串中的最后一个数字

是这样的,想请教下,SqlServer如何取出字符串中的最后一个数字
最新回答
奶气缠身

2025-06-20 10:12:44

比如你的表叫作TALBE1,字段是str1,类型为nvarchar,那么找出有湘政发的最大号加1这样写
select max(convert(int,substring(str1,patindex(N'%[1234567890]%',str1),len(str1)-patindex(N'%[1234567890]%',str1)+1-patindex(N'%[1234567890]%',reverse(str1))+1)))+1 from table1 where str1 like N'%湘政发%'
测试通过,耗时很长,请认真试试。
这是sql server 的写法。