title: Null Or Multiple Parameters When Querying
body: <p>I have a stored procedure that has a parameter that must take a <em>comma delimited</em> varchar list of values that can be turned into a table of values or can be <code>NULL</code>, such as</p>
  
  <pre><code>@Values VARCHAR(10) = NULL
  </code></pre>
  
  <p>OR</p>
  
  <pre><code>@Values VARCHAR(10) = '1,5,10' 
  
  IF OBJECT_ID('TEMPDB..#Parameters') IS NOT NULL DROP TABLE #Parameters
  CREATE TABLE #Parameters ( Id INT )
  
  INSERT INTO #Parameters
  SELECT
      [Value]
  FROM
      FunctionThatReturnsStringToTable(',',@Values)
  </code></pre>
  
  <p>I need to figure out a way to make this work in SQL like so</p>
  
  <pre><code>SELECT
     SomeColumns
  FROM
     TABLE
  WHERE
     COLUMN = IIF(@Values IS NULL, COLUMN, (SELECT Id FROM #Parameters)
  </code></pre>
  
  <p>Which I know will not work. Is there any other way around this?</p>