Conditional IN clause in SQL Server : <p>I have got a stored procedure which has five parameters. I want to include them in where clause as follows</p>

<ul>
<li>If parameter is not null then include it in query as an IN clause</li>
</ul>

<p>That is, parameter value can be like 'Test' or 'Test,Best' etc. I'm converting this comma seperated values into table using function in SQL.</p>

<p>I tried to use <code>COALESCE(@test,test_column) = test_column</code> but i'm unable to include IN clause here (What if @test = 'Test,Best').</p>

<p>So, i want to do something like mentioned below</p>

<pre><code>DECLARE @param varchar(max) = 'Test,Best';

Select * from table where CASE when @param is not null then table.column in (@param)
</code></pre>

<p>Any suggestions please.</p>
