Order By clause on a column containing string values separated by comma?

0

Please login or register to vote for this query.

(click on this box to dismiss)

Physics

Q&A for active researchers, academics and students of physics

CREATE TABLE #MyTable (EmpID INT,  Skills VARCHAR(500))


 INSERT INTO #MyTable VALUES (1  ,   'C,C++,Oracle'),
 (2    ,   'Java,JavaScript,PHP'),
 (3   ,   'C,C++,Oracle'),
( 4  ,   'JavaScript,C++,ASP'),
 (5   ,   'C,C++,JavaScript')

SELECT * FROM #MyTable
ORDER BY (
    CASE Skills
    
    WHEN '%JavaScript%'
    THEN 1
    
    WHEN 'ASP'
    THEN 2
    
    END
) ASC

DROP TABLE #MyTable

Enter Parameters

Options:
Switch sites:
loading Hold tight while we fetch your results