title: SELECT all N between @min and @max
body: <p>I need to select all numbers N (integers) between @min and @max
  Is there any way to achieve that without using a loop of some sort?</p>
  
  <p>Example:
  Let's say @min = 5, @max = 9</p>
  
  <p>I need the following values returned by my SQL query: 5,6,7,8,9</p>
  
  <p>(I'm using MSSQL 2005)</p>
  
  <p>Thanks!!</p>
  
  <p>EDIT:
  This is a solution using a custom function, which works fine.
  But it seems too much effort having to loop through all numbers manually.
  So the question is still, whether it's achievable without a loop.</p>
  
  <pre><code>CREATE FUNCTION GetAllNBetween
  (    
      @Min int,
      @Max int
  )
  RETURNS @N TABLE(n int)
  AS
  BEGIN
      WHILE @Min &lt;= @Max
      BEGIN
          INSERT INTO @N VALUES(@Min)
          SET @Min = @Min + 1
      END
      RETURN
  END
  </code></pre>
  
  <p>To be used like this:</p>
  
  <pre><code>SELECT * FROM GetAllNBetween(5, 9)
  </code></pre>