STRING_SPLIT (Transact-SQL) - SQL Server | Microsoft Docs[
^]
Available in SQL Server 2016 and later.
SELECT value FROM STRING_SPLIT(@temp, ',') ORDER BY value;
SELECT DISTINCT value FROM STRING_SPLIT(@temp, ',');
If you're using an earlier version of SQL Server, Google will find you an alternative string splitting function.