I need to fetch and show data on a webpage whose number of records may vary based on filters from around 500 records to 1 million records.
Will caching be of any use her
I will suggest use dynamic query with paging . so, when you click on specific page fetch records only for those pages. To fetch record from database from specific range use following query.
like this.
Create proc Test
@take smallint,
@skip smallint,
@orderBy nvarchar(20),
@subscriptionid smallint,
as
DECLARE @SQLQuery AS NVARCHAR(max)
SET @SQLQuery=' Select ROW_NUMBER() OVER (ORDER BY P.ProductId desc) as RowNum,* from product"
set @SQLQuery=@SQLQuery + ' and Subscriptionid='+CONVERT(nvarchar, @subscriptionid)
set @SQLQuery= ';WITH Results_CTE AS ( '+@SQLQuery
set @SQLQuery= @SQLQuery +' ) SELECT * FROM Results_CTE WHERE RowNum > '+CONVERT(nvarchar, @skip)+' AND RowNum <= '+CONVERT(nvarchar, @skip+@take) --//paging';
END
EXECUTE sp_executesql @SQLQuery