我是 SQL Server 的新手。在那我需要对以下数据进行排序
1, 1AB, 1AA, 20, 3C, 4D
进入
1, 1AA, 1AB, 3C, 4D, 20.
我的编码是
IF EXISTS ( SELECT name FROM sysobjects WHERE name = 'getIntPortion')
DROP FUNCTION getIntPortion
GO
CREATE FUNCTION dbo.getIntPortion ( @inputVarchar varchar(255))
RETURNS VARCHAR(255)
AS
BEGIN
WHILE(PATINDEX('%[^0-9]%', @inputVarchar) ) > 0
BEGIN
--then remove that one character, then continue
SET @inputVarchar = REPLACE(@inputVarchar
, SUBSTRING(@inputVarchar, PATINDEX('%[^0-9]%', @inputVarchar), 1)
, '')
END
RETURN @inputVarchar
END
SELECT km_ph_act_chapt_no FROM [KM_DB].[dbo].[km_ph_act_chapters]
ORDER BY CONVERT(INT, dbo.getIntPortion(km_ph_act_chapt_no))
因为这个 Alpha 没有订购......希望等待回复。
谢谢并恭祝安康,
提问者