SQL Server 2012 CTE Bug? -


i think found bug in sql server 2012. have following complex query uses cte row_number accomplish paging, followed subquery return total rows in single query:

with data ( ...complex query row_number() ... rownumber... ) select *, (select count(*) data) totalrows  data rownumber between 1 , 10 

what i'm finding in specific query if final query returns 5 rows, totalrows comes 8. there 5 rows. how totalrows bigger number of rows returned? i've tried query hints disabling parallel execution plans not slower, it's still not right. doing wrong or bug? there way count in 1 query?

without knowing internals of query , ensuring you're partitioning statements written...

i'd suggest getting differences because of clauses. need consistent , use either:

with data ( ...complex query row_number() ... rownumber... ) select *, (select count(*) data rownumber between 1 , 10) totalrows  data     rownumber between 1 , 10 

or

with data ( ...complex query row_number() ... rownumber... ) select *, (select count(*) data) totalrows  data 

Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -