What you are seeking is the
String_Split
function in SQL Server. This is a table valued function that will return rows from your input string.
CREATE PROCEDURE PrcName (
@anyID varchar(max)
) AS
BEGIN
SELECT *
FROM mytable
WHERE mytable.id IN (
SELECT value
FROM String_Split(@anyID, ' ')
)
END
This function is native as of SQL Server 2016. For older versions, there are numerous variants of this function available for you to create.
Reference:
STRING_SPLIT (Transact-SQL) - SQL Server | Microsoft Docs[
^]