Step 1: You can send your fruitNames as a comma separated (or any other delimiter which is not in any fruit names, ex '!'
or '|'
) string
Step 2: You need a Table Valued T-Sql Function to split a delimited string (Such as this) (say, table column name is myColumn
)
CREATE FUNCTION Split (@String nvarchar(4000), @Delimiter char(1))
RETURNS @Results TABLE (myColumn nvarchar(500))
AS
BEGIN
--Function body
RETURN @Results
END
Step 3: Write a stored procedure to compare splitted fruitenames with the table.
CREATE PROCEDURE CheckEatables
@fruitName nVarchar(4000) --Change the length as required
AS
BEGIN
SELECT FruitName, COALESCE(Eatable,0) Eatable
FROM FruitCrate fc JOIN dbo.Split(@fruitNames,',') fn
ON fc.FruitName = fn.myColumn
END