Pass the comma delimited string into your stored procedure and in your stored proc use a table valued function to convert you multi-valued parameter into a table.
CREATE PROC GetAllAnimals
@AnimalList nvarchar(max)
AS
DECLARE @Animals TABLE (Animal nvarchar(10))
INSERT INTO @Animals SELECT * FROM dbo.fnGetValueListFromMultiSelect(@AnimalList)
and then use the @Animals table to inner join in your query
Functions declared below.
For Integer (or ID) values
CREATE FUNCTION [dbo].[fnGetIdListFromMultiSelect](@String nvarchar(MAX))
RETURNS @Results TABLE ([Id] int)
AS
BEGIN
DECLARE @Delimiter CHAR(1)
DECLARE @INDEX INT
DECLARE @SLICE nvarchar(4000)
IF @String IS NULL RETURN
SET @Delimiter = ','
SET @INDEX = 1
WHILE @INDEX !=0
BEGIN
-- GET THE INDEX OF THE FIRST OCCURENCE OF THE SPLIT CHARACTER
SELECT @INDEX = CHARINDEX(@Delimiter,@STRING)
-- NOW PUSH EVERYTHING TO THE LEFT OF IT INTO THE SLICE VARIABLE
IF @INDEX !=0
BEGIN
SELECT @SLICE = LEFT(@STRING,@INDEX - 1)
-- CHOP THE ITEM REMOVED OFF THE MAIN STRING
SELECT @STRING = RIGHT(@STRING,LEN(@STRING) - @INDEX)
END
ELSE
SELECT @SLICE = @STRING
-- PUT THE ITEM INTO THE RESULTS SET
INSERT INTO @Results([Id]) VALUES(CAST(@SLICE AS INT))
-- BREAK OUT IF WE ARE DONE
IF LEN(@STRING) = 0 BREAK
END
RETURN
END
For string values
CREATE FUNCTION [dbo].[fnGetValueListFromMultiSelect](@String nvarchar(MAX))
RETURNS @Results TABLE ([Item] nvarchar(128) Primary Key)
AS
BEGIN
DECLARE @Delimiter CHAR(1)
DECLARE @INDEX INT
DECLARE @SLICE nvarchar(4000)
SET @Delimiter = ','
SET @INDEX = 1
WHILE @INDEX !=0
BEGIN
-- GET THE INDEX OF THE FIRST OCCURENCE OF THE SPLIT CHARACTER
SELECT @INDEX = CHARINDEX(@Delimiter,@STRING)
-- NOW PUSH EVERYTHING TO THE LEFT OF IT INTO THE SLICE VARIABLE
IF @INDEX !=0
BEGIN
SELECT @SLICE = LEFT(@STRING,@INDEX - 1)
-- CHOP THE ITEM REMOVED OFF THE MAIN STRING
SELECT @STRING = RIGHT(@STRING,LEN(@STRING) - @INDEX)
END
ELSE
SELECT @SLICE = @STRING
-- PUT THE ITEM INTO THE RESULTS SET
INSERT INTO @Results([Item]) VALUES(@SLICE)
-- BREAK OUT IF WE ARE DONE
IF LEN(@STRING) = 0 BREAK
END
RETURN
END