title: SQL Server: user defined function parameter
body: <p>I was wondering if it is possible to create a user-defined function that can take a parameter of varying length (as well as other parameters).</p>
  
  <p>Essentially I want to pass a parameter that then gets used in an <code>IN</code> statement. What I would like to do is have something like this:</p>
  
  <pre><code>CREATE FUNCTION ufnGetOpenNotificationValue 
      (@LegacyTypeID INT, 
       @MonthEnd DATE, 
       @YearStart DATE, 
       @YearEnd DATE)
  </code></pre>
  
  <p>Where <code>@LegacyTypeID</code> is a list of integers.</p>
  
  <p>So then using the function might look something like this</p>
  
  <pre><code>SELECT RE_Auxiliary.dbo.ufnGetOpenNotificationValue
      ((1,2,3),'2014-07-31','2013-09-01','2014-08-31')
  </code></pre>
  
  <p>rather than</p>
  
  <pre><code>SELECT RE_Auxiliary.dbo.ufnGetOpenNotificationValue
          (1,'2014-07-31','2013-09-01','2014-08-31') + 
      RE_Auxiliary.dbo.ufnGetOpenNotificationValue
          (2,'2014-07-31','2013-09-01','2014-08-31') + 
      RE_Auxiliary.dbo.ufnGetOpenNotificationValue
          (3,'2014-07-31','2013-09-01','2014-08-31')
  </code></pre>
  
  <p>but if I try and pass multiple integers I get an error stating</p>
  
  <pre><code>Incorrect syntax near ','
  </code></pre>