title: dynamic pivot in SQL Server
body: <p>I have a query that uses both pivot and unpivot at the same time and I got it working fine. The code is part of a stored procedure that gets called from a Excel Macro when user passes in the parameters from the form.</p>
  
  <p>I cant seem to think of a way of making my "IN" string dynamic. The IN part is something like</p>
  
  <pre><code>pivot
    (
    Sum(numbers) for
  
    WeekNum in ([12*02],[12*03],[12*04],[12*05],[12*06],[12*07],[12*08],[12*09],[12*10],[12*11],[12*12],[12*13])
    ) as q
  </code></pre>
  
  <p>I am trying to make the IN clause dynamic. So, if a user types in 12*04 as their starting range and 12*16 as their ending range, the above code should change dynamically. I could pass the entire query as a string and then update it, but I am not sure if that would work. 
  Any thoughts?</p>