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