I wish there were array vars like that! :-)
But you can convert it to a table
using a function, and then use the table
with your IN clause as you're attempting.
Here is how that would look:
DECLARE @Param1 nvarchar(max)
SET @Param1 = 'Test,Test1,Test2'
SELECT *
FROM myTable
WHERE myField In (Select ParsedString From dbo.ParseStringList(@Param1))
And here is (at least one way to write) the function:
CREATE Function [dbo].[ParseStringList] (@StringArray nvarchar(max) )
Returns @tbl_string Table (ParsedString nvarchar(max)) As
BEGIN
DECLARE @end Int,
@start Int
SET @stringArray = @StringArray + ','
SET @start=1
SET @end=1
WHILE @end<Len(@StringArray)
BEGIN
SET @end = CharIndex(',', @StringArray, @end)
INSERT INTO @tbl_string
SELECT
Substring(@StringArray, @start, @end-@start)
SET @start=@end+1
SET @end = @end+1
END
RETURN
END