title: Sql server exception: the statement did not return a result set
body: <p>I have a SQL query that runs fine in SQL Server Management Studio, but when I copy and paste it into jasperreports's iReport to make a report, it gives me a SQL Server exception and says the statement did not return a result set. This has left me confused.</p>
  
  <p>The query is: </p>
  
  <pre><code>declare @index int = 1
  
  declare @t Table(ID INT, DI INT, INDBOOK1 INT, INDBOOK2 INT, delta INT)
  
  while(@index &lt; 18)
  begin
     INSERT INTO @t
        select distinct top 18
           col1.ID,
           col1.DI,
           col1.INDBOOK as INDBOOK1,
           col2.INDBOOK as INDBOOK2,
           col2.INDBOOK - col1.INDBOOK 
        FROM  
            table as col1
        inner join 
            table as col2 on col2.ID = @index 
                          and col2.DI = col1.DI+1 
        where 
            col1.ID = @index
  
     set @index = @index + 1
  end
  
  select ID, DI, INDBOOK1, INDBOOK2, delta FROM @t
  </code></pre>
  
  <p>Does anybody know why this is giving me the no result set returned exception?</p>
  
  <p>Any help appreciated.</p>