title: Passing sets and optional parameters to a stored procedure T-SQL - ASP.NET
body: <p>I have an <strong>aspx page</strong> with the following controls: <strong>TextBox, CheckBoxList, DropDownList</strong>.
  They are used to specify search criteria. The records are taken from <strong>SQL Server Data Base</strong> using a stored procedure.</p>
  <ol>
  <li><p>Each <strong>CheckBox</strong> in <strong>CheckBoxList</strong> has a value which is actual ID of a Product Group in the database. If more than one checkbox is selected, how to pass the list of IDs to a stored procedure as a set so I could use <strong>IN @IdList</strong>? What variable types should I use in C# and T-SQL? Is it possible at all?</p>
  </li>
  <li><p><strong>DropDownList</strong>'s first item is &quot;ALL&quot;. When &quot;ALL&quot; is selected, I need to pass something like <strong>NULL</strong> to the stored procedure. How to make the stored procedure to ignore a parameter if it is <strong>NULL</strong>?</p>
  <p>CREATE PROCEDURE FilterList
  @ProductName nvarchar(200),
  @ProductGroupID int
  AS BEGIN
  SELECT
  prod_id AS 'ID',
  prod_name AS 'Name'
  FROM
  dbo.Products
  WHERE
  prod_group_id = @ProductGroupID OR
  prod_name = @ProductName
  END</p>
  </li>
  </ol>