Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Date Difference and Filtering on date difference

Status
Not open for further replies.

t16turbo

Programmer
Joined
Mar 22, 2005
Messages
315
Location
GB
Hi guys,

I have the following SQL that returns time transactions - including fields for Entry Date Transaction Date and Quantity of time booked:
Code:
SELECT * FROM (SELECT ENTRYDATE, TRANSDATE, QUANTITY, COMPANY_CODE, PROJECT_CODE, RESOURCE_CODE, TASK_ID, CHARGE_CODE FROM
niku.PPA_WIP

UNION ALL
SELECT ENTRYDATE, TRANSDATE, QUANTITY, COMPANY_CODE, PROJECT_CODE, RESOURCE_CODE, TASK_ID, CHARGE_CODE FROM
niku.PPA_TRANSCONTROL) a
WHERE COMPANY_CODE = 'DST01UKT'

I need to display another column showing the number of days between the ENTRYDATE and TRANSDATE.
I also need a criteria that will only display the results where the TRANSDATE is a week or more BEFORE the ENTRYDATE.
(7 days +)
can anyone help?
 
Turbo,

Oracle's date-handling capabilities are probably the strongest in the industry. Here is a version of your code that, I believe, does what you want (additions in bold):
Code:
SELECT * FROM (SELECT ENTRYDATE, TRANSDATE, [b]ENTRYDATE-TRANSDATE delta_days[/b], QUANTITY, COMPANY_CODE, PROJECT_CODE, RESOURCE_CODE, TASK_ID, CHARGE_CODE FROM
niku.PPA_WIP
[b]WHERE ENTRYDATE-TRANSDATE > 7[/b] 

UNION ALL
SELECT ENTRYDATE, TRANSDATE, [b]ENTRYDATE-TRANSDATE[/b], QUANTITY, COMPANY_CODE, PROJECT_CODE, RESOURCE_CODE, TASK_ID, CHARGE_CODE FROM
niku.PPA_TRANSCONTROL
[b]WHERE ENTRYDATE-TRANSDATE > 7[/b]) a
WHERE COMPANY_CODE = 'DST01UKT'

 [santa]Mufasa
(aka Dave of Sandy, Utah, USA)
[[URL unfurl="true"]www.dasages.com:[/URL] Providing low-cost remote Database Admin services]
Click here to join [url=http://tek-tips.com/threadminder.cfm?pid=1426]Utah Oracle Users Group on Tek-Tips[/url] if you use [b]Oracle[/b] in [b]Utah[/b] USA.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top