
Originally Posted by
EricRex
Hey there,
I know I'm pushing the boundaries here, but my use case demands that I try to do this for multiple forms doing the same basic queries with several different sets of criteria.
I have a saved query named QryNumTrades with SQL =
PARAMETERS startDate Date, endDate Date, andClause Text;
SELECT Count (cPosSizeR) AS fieldValue FROM StockTrades WHERE TradeDate >= startDate AND TradeDate <= endDate AND [andClause];
Hey all,
Still pushing the boundaries here. After a lot of trials and errors, I finally found a webpage with mostly what I'm trying to do with parameterizing my Columns in a saved Query:
That website is: https://stackoverflow.com/questions/...lect-the-field
My version below is much, much uglier than his because I have more column choices, but it makes my code much, much cleaner, and gets rid of a bunch of spurious tables with summary info and queries that were mostly identical to each other except the primary Select and Group By column name. By the way, this is the simplest of my 4 Saved Parameter Queries because there's not much info on Trades that made exactly zero dollars. Winning and Losing Trades have 13 fields each! And the Summary Stats have another 9 or so.
Code:
PARAMETERS [ResultsBy] Text ( 255 );
SELECT Switch
(
[ResultsBy] = 'Direction', [Direction],
[ResultsBy] = 'Pattern', [Pattern],
[ResultsBy] = 'Weekday', [cWeekday],
[ResultsBy] = 'EntryOrder', [EntryOrder],
[ResultsBy] = 'ExitOrder', [ExitOrder],
[ResultsBy] = 'Symbol', [Symbol],
[ResultsBy] = 'Summary', "Scratches"
) AS Label1, Count(cPosSizeR) AS NumScratch, Round(COUNT(cPosSizeR) / (SELECT COUNT(cPosSizeR) FROM StockTrades) * 100, 2) AS PctScratch
FROM StockTrades
WHERE cPosSizeR = 0
GROUP BY Switch
(
[ResultsBy] = 'Direction', [Direction],
[ResultsBy] = 'Pattern', [Pattern],
[ResultsBy] = 'Weekday', [cWeekday],
[ResultsBy] = 'EntryOrder', [EntryOrder],
[ResultsBy] = 'ExitOrder', [ExitOrder],
[ResultsBy] = 'Symbol', [Symbol],
[ResultsBy] = 'Summary', "Scratches"
);
I would still love to figure out how to parameterize the [cPosSizeR] > 0 (or = 0, or < 0) and I have to figure out how to add my ORDER BY Clause for weekdays. But this is so close!
Cheers,
Eric