标签:pre charindex 排序 add function 序号 cti string sequence
解决思路:计算每位的权重,得到序号完整的权重值,使用权重值进行排序!
创建sql 函数如下:
ALTER FUNCTION [dbo].[SequenceToOrderNum] ( @Sequence VARCHAR(50) ) RETURNS INT BEGIN DECLARE @Count INT DECLARE @OrderNum INT SET @Count = 6 --根据需求改变 SET @OrderNum = 0 WHILE CHARINDEX(‘.‘, @Sequence) > 0 BEGIN SET @OrderNum = @OrderNum + CAST(SUBSTRING(@Sequence, 0, CHARINDEX(‘.‘, @Sequence)) AS NUMERIC) * POWER(20, @Count)--根据需求改变 SET @Sequence = SUBSTRING(@Sequence, CHARINDEX(‘.‘, @Sequence) + 1, LEN(@Sequence)) SET @Count = @Count - 1 END SET @OrderNum = @OrderNum + CAST(@Sequence AS NUMERIC) * POWER(20,---根据需求改变 @Count) RETURN @OrderNum END --结果: 3.3.1.3.1=>201784400
标签:pre charindex 排序 add function 序号 cti string sequence
原文地址:http://www.cnblogs.com/mengkai/p/7827662.html