我正在尝试对一个包含字母数字字母的列进行排序
请参阅下面的查询
SELECT d.number
FROM table name d, table_name 2 a WHERE d.case_id ='11-41'
AND d.ExhibitTypeId = TypeId AND d.ComplianceNo = '0' and
active = 1 and number is not null order by case
when ISNUMERIC(d.number) = 1 then right('0000000000'+d.number+'0',10)
else right('0000000000'+d.number,10)
end
这是输出
1
2
3
11
12
2A1
我想要这个输出
1
2
2A1
3
11
12
非常感谢有关此方面的任何帮助。
答案 0 :(得分:0)
假设SQL Server可以使用一些调整
SELECT
d.number
FROM
table name d,
table_name 2 a
WHERE
d.case_id ='11-41'
AND
d.ExhibitTypeId = TypeId
AND
d.ComplianceNo = '0'
and
active = 1
and number is not null
order by
Convert(int, LEFT(number, Case
When PATINDEX('%[^0-9]%', number) > 0 Then PATINDEX('%[^0-9]%', number) - 1
Else LEN(number)
End)
),
LEN(Number)
答案 1 :(得分:0)
如果(ISNUMERIC(LEFT(情况下,2)
BEGIN
逐个案例
END
其他
BEGIN
LEFT(case,1),LEFT(case,2)
的顺序END