Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

Loop Query Through Date Range

$
0
0

Hi all,

I'm currently running a SQL script within Excel VBA.

VBA loops through this script for every date that appears in a table. The dates are contiguous, but the start and end dates change based on other variables in the spreadsheet.

This works great but is however very slow and it might query the database 1000 times to pull back a fairly simple table.

What I'm trying to do is move this loop into the SQL script to speed things up a bit but I don't really know where to start. Ideally the only variables would be the start date and the end date. SQL would then build a table with every date in between and run the existing query against every date therein.

Could someone give me a starting point please? Even if its just some ideas of keywords to search for.

Thanks,

Dan.


Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>