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 
(
	SELECT *
    ,(CASE WHEN Skills LIKE '%JavaScript%' THEN 0 WHEN Skills LIKE '%ASP%' THEN 1 END) AS Rnk 
	FROM #MyTable
) T
ORDER BY rnk,EmpID


DROP TABLE #MyTable

Enter Parameters

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