Created
January 22, 2024 21:57
-
-
Save Tomamais/1b5cd411f33a698e28b5b09efc417ff2 to your computer and use it in GitHub Desktop.
This file contains 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