I think there is a better solution. You can create a function such as:
CREATE FUNCTION [dbo].[Split] (@sep char(1), @s varchar(8000)) RETURNS table AS RETURN ( WITH Pieces(pn, start, [stop]) AS ( SELECT 1, 1, CHARINDEX(@sep, @s) UNION ALL SELECT pn + 1, [stop] + 1, CHARINDEX(@sep, @s, [stop] + 1) FROM Pieces WHERE [stop] > 0 ) SELECT pn as [index], SUBSTRING(@s, start, CASE WHEN [stop] > 0 THEN [stop]-start ELSE 8000 END) AS value FROM Pieces )
Then you can get the result for input '20,10,15,18,19'
SELECT * FROM [dbo].[Split](',', '20,10,15,18,19')
The result will be:
index value 1 20 2 10 3 15 4 18 5 19
And I can rewrite your procedure as shown below:
Create Proc dbo.GetApplicantsByIDs @Ids NVARCHAR(MAX) as Select * from Applicants where ID in (SELECT value FROM [dbo].[Split](',', @Ids)
source share