Link to home
Start Free TrialLog in
Avatar of tmccull2
tmccull2Flag for United States of America

asked on

Microsoft Query / SQL

I need help adding paramters (begindate1,enddate1,begindate2,enddate2) to replace the hard coded dates in this sql statement. The statement below works fine in Microsoft Query and returns the data to Excel 2003. I'd like the parameters to be populated by cell values in the Excel worksheet.  Thanks!

SELECT Principal,    SUM(Case When Date BETWEEN '1-1-2006 00:00:00.000' AND '12-31-2006 00:00:00.000' THEN Amount else 0 end),    SUM(Case When Date BETWEEN '1-1-2007 00:00:00.000' AND '12-31-2007 00:00:00.000' THEN Amount else 0 end)     FROM dbo.Results    GROUP BY Principal    ORDER BY Principal ASC
Avatar of Rory Archibald
Rory Archibald
Flag of United Kingdom of Great Britain and Northern Ireland image

I don't think that query can be represented graphically in MS Query and you can't use parameters in such cases. You may be better off using ADO or rewriting your query to group by YEAR(Date)
Regards,
Rory
Avatar of tmccull2

ASKER

Thank you for your response.

If my goal is to be able to compare two date ranges such as current 52 weeks vs. YAGO and update the dates from Excel cell values, can you offer me an example to get started?

Thanks Terry
ASKER CERTIFIED SOLUTION
Avatar of Rory Archibald
Rory Archibald
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial