Solved

Limiting report data

Posted on 2013-01-07
7
149 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

PL/SQL can be a very powerful tool for working directly with database tables. Being able to loop will allow you to perform more complex operations, but can be a little tricky to write correctly. This article will provide examples of basic loops alon…
If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

929 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

16 Experts available now in Live!

Get 1:1 Help Now