The problem:
I want the end of a WHERE-clause to depend on a variable, called @filter that lists a number of integer values. For instance, if I want to filter for the values 2 and 3, this would be the end of the WHERE clause:
.
.
.
AND section.ID in (2,3)
But I haven't been able to work out how to use @filter here. If I do this:
declare @filter NVARCHAR(30) = 'sektion.resourceTypeID in (2,3)';
.
.
.
AND @filter
I get an error saying "An expression of non-boolean type specified in a cotext where a condition is expected.
" And if I try this:
declare @filter NVARCHAR(30) = '2,3';
.
.
.
AND sektion.resourceTypeID in (@filter)
I can run the query, but get an error saying conversion from NVARCHAR to INT failed. How do I solve this?