Created
January 22, 2024 21:57
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Tested on SQL Server 2019 | |
DECLARE @inputString NVARCHAR(100) = '1,3,2,4,2'; | |
SELECT STUFF(( | |
SELECT ',' + CAST(value AS NVARCHAR(MAX)) | |
FROM STRING_SPLIT(@inputString, ',') | |
ORDER BY CAST(value AS INT) | |
FOR XML PATH('') | |
), 1, 1, '') AS SortedString; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment