I have a stored procedure which has a parameter @SomeFilterIds, which takes in comma separated integer ids. If this parameter is not NULL it is translated into something like this:
AND [X] IN(1, 2, 4)
and assigned to @SomeFilter
I then used something along those lines:
SET @Sql = N' ...WHERE
c.SomeDate >= @SomeDate
' + @SomeFilter
and:
SET @ParameterDefinition = N'@SomeDate DateTime';
EXEC sp_executesql
@Sql
,@ParameterDefinition
,@SomeDate = @SomeDate
I would think that this is not best practice and opens potential security holes. Is this correct? Can this be improved? Thanks.