title: Why does this query return more than ten rows?
body: <p>why does the code below return more than 10 rows? I've also tried including a <code>top 10</code> in the <code>sub-query</code>, but that didn't work either.</p>
  
  <pre><code>select top 10
  total_worker_time/execution_count as avg_cpu_cost, query_plan,
  execution_count,
  (select substring(text, statement_start_offset/2 + 1,
      (case when statement_end_offset = -1
      then len(convert(varchar(max), text))* 2
      else statement_end_offset
      end - statement_start_offset)/2)
  from sys.dm_exec_sql_text(sql_handle)) as query_text
  from sys.dm_exec_query_stats
  CROSS APPLY sys.dm_exec_query_plan(plan_handle)
  order by [avg_cpu_cost] desc
  </code></pre>