title: T-SQL validation for dates in a loop?
body: <p>I an working with financial time series. I have a user defined function that tells me the previous available trading date for some security. I am now trying to wrtie a user defined function that will compute volatility, to do this, I need to check that there is data for the previous n trading days. </p>
  
  <p>My date function returns Null if there is no previous trading day. What is a good way to check for the <code>n</code> previous trading days? Suppose the function is called <code>previous</code> and takes as parameters the security <code>id</code> and <code>date</code> (and it then checks if there is trading date prior to this date).</p>
  
  <p>I would need to run some sort of a loop?</p>