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 [email protected] + 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
Getordervalue Sort SQL Server