Solved

Limiting report data

Posted on 2013-01-07
7
152 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

The New “Normal” in Modern Enterprise Operations

DevOps for the modern enterprise offers many benefits — increased agility, productivity, and more, but digital transformation isn’t easy, especially if you’re not addressing the right issues. Register for the webinar to dive into the “new normal” for enterprise modern ops.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
sql help 8 59
SQL Query 26 68
SYbase 4 37
add criteria to query in VB, Access 2003 2 13
'Between' is such a common word we rarely think about it but in SQL it has a very specific definition we should be aware of. While most database vendors will have their own unique phrases to describe it (see references at end) the concept in common …
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…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

820 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