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)

Robotics Meta

Q&A about the site for professional robotic engineers, hobbyists, researchers and students

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 ELSE 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