34,576
社区成员
发帖
与我相关
我的任务
分享
select *
from
(
select 'XX-YY-123' as serial_str union select 'YY-DD-LL-7'
) my_table
order by cast(right(serial_str,charindex('-',reverse(serial_str))-1) as int)
/*
serial_str
----------
YY-DD-LL-7
XX-YY-123
(所影响的行数为 2 行)
*/
order by cast(right(serial_str,charindex('-',reverse(serial_str))-1) as int)
order by len(serial_str),serial_str
declare @tb table ( serial_str nvarchar(10))
insert into @tb select 'xx-yy-123'
union all select 'yy-dd-ll-7'
select * from @tb order by cast (right( serial_str,charindex('-',reverse(serial_str))-1) as int)
serial_str
----------
yy-dd-ll-7
xx-yy-123
(2 行受影响)