27,579
社区成员
发帖
与我相关
我的任务
分享
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]
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