Solved

Limiting report data

Posted on 2013-01-07
7
148 Views
Last Modified: 2013-01-13
Follow up to this question.

I want to change this query:
SELECT *
FROM [Project List] LEFT JOIN (SELECT * FROM Comments WHERE Comments.[Comment Date]>DateAdd("d",-14,date()))  AS q ON [Project List].ID=q.[Project ID]
WHERE ((([Project List].Resource)=[ResourceFilter]));

Open in new window


So that it does not return projects that are "completed" with a completion date > 14 days ago.

Relevant fields:
[Project List].[Closed Date]
[Project List].[Status]

Open in new window


The value for "Status" for completed projects is "99 Complete"
0
Comment
Question by:nap0leon
  • 4
  • 3
7 Comments
 
LVL 8

Expert Comment

by:Barry62
ID: 38751649
SELECT *
FROM [Project List] LEFT JOIN (SELECT * FROM Comments WHERE Comments.[Comment Date]>DateAdd("d",-14,date()))  AS q ON [Project List].ID=q.[Project ID]
WHERE [Project List].[Status] = "99 Complete" and ([Project List].[Closed Date] < DATE_SUB(date,INTERVAL 14 DAY)) and ((([Project List].Resource)=[ResourceFilter]));

Open in new window

0
 
LVL 18

Accepted Solution

by:
nap0leon earned 0 total points
ID: 38751824
Correcting the above for syntax errors, I have:
SELECT *
FROM [Project List] LEFT JOIN (SELECT * FROM Comments WHERE Comments.[Comment Date]>DateAdd("d",-14,date()))  AS q ON [Project List].ID=q.[Project ID]
WHERE ([Project List].[Status] = "99 Complete" and ([Project List].[Closed Date] < DateAdd("d",-14,date())) and ([Project List].Resource)=[ResourceFilter]);

Open in new window


However, this returns only projects that are closed less than 14 days ago.  I need it to ignore items that are closed more than 2 weeks ago.

I've come up with the following, which ignores the Status field and instead relies only on the value of "Complete Date":
SELECT *
FROM [Project List] LEFT JOIN (SELECT * FROM Comments WHERE Comments.[Comment Date]>DateAdd("d",-14,date()))  AS q ON [Project List].ID=q.[Project ID]
WHERE (([Project List].[Closed Date]>DateAdd("d",-14,date()) Or ([Project List].[Closed Date] Is Null)) And ([Project List].Resource)=[ResourceFilter]);

Open in new window

0
 
LVL 18

Author Comment

by:nap0leon
ID: 38754875
I've requested that this question be deleted for the following reason:

Solved it myself
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 8

Expert Comment

by:Barry62
ID: 38754876
Although my syntax was a bit off, I did provide you with the mysql function (date_sub) which inspired your fix.
0
 
LVL 18

Author Comment

by:nap0leon
ID: 38754996
Actually no.  

I had already decided that I did not need to look at "Status" and would instead simply filter on "Closed Date".

For the Projects Filter, I am using the DateAdd (the same as I am already using in the Comments filter section) and a test that allows NULL.

Besides... You had it backwards (showing only stuff that was closed in the past two weeks rather than showing everything except what was closed over 2 weeks ago.

Thank you for trying, but, honestly, I used absolutely nothing from your solution.
0
 
LVL 8

Expert Comment

by:Barry62
ID: 38755883
Fair enough.  I tried.  I won't object to you closing the question.
0
 
LVL 18

Author Closing Comment

by:nap0leon
ID: 38771606
Solved it myself
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

If you find yourself in this situation “I have used SELECT DISTINCT but I’m getting duplicates” then I'm sorry to say you are using the wrong SQL technique as it only does one thing which is: produces whole rows that are unique. If the results you a…
Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now