还是排序.如果先按数字,后按字母排序.

poloyzhang 2014-12-09 04:46:12


use TempTest
go
if OBJECT_ID ('Tb1') is not null drop table Tb1
Create Table Tb1 (
colKey varchar(10) not null primary key ,
col1 varchar(10) null,
col2 varchar (10) null
)
go


Insert into Tb1
Select 'A1' , 'c1' , 'c2' union all
Select '1' , 'c2' , 'c3' union all
Select '99' , 'c3' , 'c4' union all
Select '3' , 'c4' , 'c5' union all
Select '4' , 'c5' , 'c6' union all
Select '999999' , 'c6' , 'c7' union all
Select '6' , 'c7' , 'c8' union all
Select 'A8' , 'c8' , 'c9' union all
Select 'A9' , 'c9' , 'c10' union all
Select '7' , 'c10' , 'c11' union all
Select '9999' , 'c11' , 'c12' union all
Select '9' , 'c12' , 'c13' union all
Select '9999999' , 'c13' , 'c14' union all
Select 'A10' , 'c14' , 'c15' union all
Select '12' , 'c15' , 'c16' union all
Select '13' , 'c16' , 'c17' union all
Select '99999999' , 'c17' , 'c18' union all
Select '15' , 'c18' , 'c19' union all
Select '16' , 'c19' , 'c20' union all
Select '99999' , 'c20' , 'c21'


SELECT * FROM [TempTest].[dbo].[Tb1]
...全文
400 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
还在加载中灬 2014-12-09
  • 打赏
  • 举报
回复
是这个意思吗
SELECT * FROM [dbo].[Tb1]
ORDER BY ISNUMERIC(colKey)DESC
	,CASE WHEN ISNUMERIC(colKey)=1 THEN CAST(colKey AS INT)END
	,CASE WHEN ISNUMERIC(colKey)=0 THEN CAST(SUBSTRING(colKey,2,LEN(colKey)) AS INT)END
poloyzhang 2014-12-09
  • 打赏
  • 举报
回复
colKey 列 如何 先按数字从小到大, 后按字母 排序.

27,579

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 应用实例
社区管理员
  • 应用实例社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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