如何使用Alpha数字的排序依据 [英] How Can I Use Order By For Alpha Numeric
本文介绍了如何使用Alpha数字的排序依据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
我需要使用order by for alphanumeric。我有3个领域即
NAS9998
NAS9999
NAS10000
当我发出订单时,它首先显示NAS10000。我怎么能解决这个问题。
请帮帮我
谢谢
Afsal
解决方案
创建 < span class =code-keyword> table ## Table(id bigint identity ( 1 , 1 ),代码 nvarchar ( max))
insert 进入 ##表(代码)值(' NAS9998')
< span class =code-keyword> insert Into ## Table(code) values (' NAS9999')
insert Int o ##表(代码)值(' NAS10000')
选择 * 来自 ##表订单 按 Cast(substring(code, 4 , 100 ) as bigint ) ASC
是的,你可以。如果您想按数字排序,则需要提取数字部分,例如:
SELECT FieldName, LEFT (FieldName, 3 ) AS FirstPart, CONVERT ( INT , RIGHT (FieldName,LEN(FieldName)-3)) AS SecondPart
FROM TableName
ORDER BY CONVERT ( INT , RIGHT (FieldName,LEN(FieldName)-3)) ASC 跨度>
Hi All,
I need to use order by for alphanumeric. i have 3 fields namely
NAS9998
NAS9999
NAS10000
when i give order by it shows NAS10000 in first. How can i solve this.
please help me
Thanks
Afsal
解决方案
Create table ##Table(id bigint identity(1,1),code nvarchar(max)) insert Into ##Table(code)values('NAS9998') insert Into ##Table(code)values('NAS9999') insert Into ##Table(code)values('NAS10000') select * From ##Table order by Cast(substring(code,4,100) as bigint) ASC
Yes, you can. In case you want to sort by numbers, you need to extract numeric part, for example:
SELECT FieldName, LEFT(FieldName, 3) AS FirstPart, CONVERT(INT, RIGHT(FieldName, LEN(FieldName)-3)) AS SecondPart FROM TableName ORDER BY CONVERT(INT, RIGHT(FieldName, LEN(FieldName)-3)) ASC
这篇关于如何使用Alpha数字的排序依据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文