getOrderValue 排序 sql server
GO
-- =============================================
-- Author: <Author,,rx.tang>
-- Create date: <Create Date, ,>
-- Description: <Description, ,get order value>
-- =============================================
CREATE FUNCTION [dbo].[getOrderValue]
(
-- Add the parameters for the function here
@v VARCHAR(50)
)
RETURNS VARCHAR(8000)
AS
BEGIN
DECLARE @r VARCHAR(8000)
DECLARE @number VARCHAR(50)
DECLARE @splite INT
SET @r =‘‘
IF( @v is null or LEN(@v) = 0)
BEGIN
RETURN ‘‘
END
WHILE(1=1)
BEGIN
set @splite = patindex(‘%[0-9]%‘,@v)
IF(@splite > 0)
BEGIN
SET @r =@r + LEFT(@v,@splite-1)
SET @v = RIGHT(@v, LEN(@v)- @splite +1 )
SET @splite = patindex(‘%[^0-9]%‘,@v)
IF(@splite > 0)
BEGIN
SET @number = LEFT(@v,@splite-1)
SET @r = @r + RIGHT(‘000000000000000000000000‘ + @number,10)
SET @v = RIGHT(@v, LEN(@v)- @splite +1 )
END
ELSE
BEGIN
SET @r = @r + RIGHT(‘000000000000000000000000‘ + @v,10)
BREAK
END
END
ELSE
BEGIN
BREAK
END
END
RETURN @r
END
GO
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。