SQL Split Function and Ordering Issue?

后端 未结 5 1135
小鲜肉
小鲜肉 2021-01-18 03:53

I have the following Split function,

ALTER FUNCTION [dbo].[Split](@String varchar(8000), @Delimiter char(1))     
                returns @tempt         


        
5条回答
  •  走了就别回头了
    2021-01-18 04:27

    declare @Version nvarchar(3000)
    declare @Delimiter char(1) = ','
    declare @result nvarchar(3000)
    set @Version = 'Terça-feira, Quarta-feira, Sexta-feira, Segunda-feira';
    
    with V as (select value v, Row_Number() over (order by (select 0)) n 
        from String_Split(@Version, @Delimiter)
    )
        SELECT @result = STUFF((SELECT ', ' + RTRIM(LTRIM(v))
          FROM V
          ORDER BY CASE RTRIM(LTRIM(v))
                WHEN 'Segunda-feira' then 1 
                WHEN 'Terça-feira' then 2
                WHEN 'Quarta-feira' then 3 
                WHEN 'Quinta-feira' then 4 
                WHEN 'Sexta-feira' then 5
               END FOR XML PATH('')), 1, LEN(@Delimiter), '')
    PRINT @result
    

提交回复
热议问题