Run Query using Multiple Parameters

E

eoin.corrigan

Hi - thanks in advance for help.

I have this query that will calcuate my positions on any day that
enter.

SELECT StockTransactions.DealCode, StockTransactions.Stock,
Sum(StockTransactions.Shares) AS SumOfShares
FROM StockTransactions
WHERE StockTransactions.TradeDate<[As Of]
GROUP BY StockTransactions.DealCode, StockTransactions.Stock
HAVING Sum(StockTransactions.Shares)>0;

However, I'd like to have the query run for every day between two
dates that I enter.

So, if I input start date as Jan 1 and end date as Jan 15 it will run
the above query repeatdly using Jan 1 as [As Of], Jan 2 as [As Of],
Jan 3 as [As Of],.....Jan 15 as [As Of].

Hope it's clear and thanks again!
 
K

KARL DEWEY

Use this --
WHERE StockTransactions.TradeDate BETWEEN [Enter start] AND [Enter end]
 
J

John Spencer

I would use something like the following

PARAMETERS [StartDate] Datetime,
[End Date (blank for one day)] DateTime;
SELECT TradeDate
, StockTransactions.DealCode
, StockTransactions.Stock
, Sum(StockTransactions.Shares) AS SumOfShares
FROM StockTransactions
WHERE StockTransactions.TradeDate Between [Start Date]
And NZ([End Date (blank for one day)],Start Date])
GROUP BY TradeDate, StockTransactions.DealCode, StockTransactions.Stock
HAVING Sum(StockTransactions.Shares)>0;

--
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
..
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top