I would suggest you to handle this issue in SQL implementation. Just the optional.
To pass text parameter and hope it works as a list, you should represent them in table, after then join your query result to that list in the table. See code below:
Create new table variable and insert each member in the list into the table:
DECLARE @SelectedDeptIds table
(
DeptID int
)
DECLARE @deptIdTemp varchar(10), @Pos int
SET @Para_DID = LTRIM(RTRIM(@Para_DID))+ ','
SET @Pos = CHARINDEX(',', @Para_DID, 1)
IF REPLACE(@Para_DID, ',', '') <> ''
BEGIN
WHILE @Pos > 0
BEGIN
SET @deptIdTemp = LTRIM(RTRIM(LEFT(@Para_DID, @Pos - 1)))
IF @deptIdTemp <> ''
BEGIN
INSERT INTO @SelectedDeptIds (DeptID) VALUES (CAST(@deptIdTemp AS int))
END
SET @Para_DID = RIGHT(@Para_DID, LEN(@Para_DID) - @Pos)
SET @Pos = CHARINDEX(',', @Para_DID, 1)
END
END
Next code is to join table to the list:
SELECT c.DeptID, c.Department, b.Course_Name, b.Course_ID, b.Type, b.Ref_Code, b.Exam
FROM dbo.db_Competency_List AS a INNER JOIN
dbo.db_Course AS b ON a.Course_ID = b.Course_ID INNER JOIN
dbo.db_Department AS c ON a.Dept_ID = c.DeptID
INNER JOIN @SelectedDeptIds d ON a.Dept_ID = d.DeptID