Another SQL question - Please assist :)
Ok, there are 6 pilots total, all of which has a pil_pt135_date that is older then the current date.
The dates are:
01-15-07
04-12-07
05-23-07
06-21-07
07-24-07
08-07-07
Those that are older then 6 months from today is the first date I listed (1/15/07). Run this query and you'll get that.
The only downside to this is that it doesn't account for actual months. It's based upon a month = 30 days @ 6 months or 180 days. I honestly don't see your teacher caring that much for an intro to database class. But in the event they care, you'll just need to make the DateADD function work.
The dates are:
01-15-07
04-12-07
05-23-07
06-21-07
07-24-07
08-07-07
Those that are older then 6 months from today is the first date I listed (1/15/07). Run this query and you'll get that.
Code:
SELECT (e.emp_fname ||' '|| e.emp_lname) Pilot, p.pil_pt135_date FROM hartmar.employee e join hartmar.pilot p on e.emp_num = p.emp_num WHERE p.pil_pt135_Date < (CURRENT_DATE - 180);
Last edited by dieneverknowing; Oct 4, 2007 at 08:31 AM.

But from what you sent me I think I have it. If you ignore the "tested every six month" you basically need to find the pilots that fit two different ranges.
Range 1: "The Past" <-----------| "Today"
Range 2: "Today" |----------| "3 Months from today"
If you accomplish Range 2, then you accomplish both. If you check for dates that occur before the 3 month point then you are actually checking every date before it including days older then today.
Mega Range: "Past" <----------- "Today" ----------| "3 mos from Today"
So in your 'WHERE' clause check to find dates older then 3 mos from today. Once you get that I'll give you the next part unless you figure that out
WHERE dateadd('mm',-3,sysdate) > P.pil_pt135_date
*
ERROR at line 3:
ORA-00904: "DATEADD": invalid identifier
*
ERROR at line 3:
ORA-00904: "DATEADD": invalid identifier
You don't need the DateAdd to run this query. As well as no extra variables. One mistake coders make is that they quickly will make extra variables then they need. This example shows why you don't need to do that which in the long run will save you storage space and query time.
Try this.
That should be all you need to find pilots who have an over due date or a date within 3 months. It outputs the Pilot, their last test date and the estimated next test date as per what you sent me.
Try this.
Code:
SELECT (e.emp_fname ||' '|| e.emp_lname) Pilot, p.pil_pt135_date "Last Proficiency Test", (p.pil_pt135_date + 180) "Next Proficiency Test" FROM hartmar.employee e join hartmar.pilot p on e.emp_num=P.emp_num WHERE p.pil_pt135_Date < (CURRENT_DATE + 90);
I'm learning to add and delete entries in a database now(Via embedded programming) and Visual Studio in my computer lab won't compile anything, I don't think they installed it correctly.
What version of VS are you running? And what build errors are you getting?
8.0.5
They aren't build errors, it says "fatal error C1083: Cannot open source file: '.\main.cpp': No such file or directory" Its happened on every computer I've tried it. I'm going to see if my boss will fix it.
They aren't build errors, it says "fatal error C1083: Cannot open source file: '.\main.cpp': No such file or directory" Its happened on every computer I've tried it. I'm going to see if my boss will fix it.
So I tried to use IF ELSE but I don't think I used it right because I get an error. Not even sure if this is close:
Code:
TTITLE 'RobAir - Pilot Proficiency Test Status' COLUMN pil_pt135_date - HEADING 'Last Proficiency Test' COLUMN req_pt135_date - HEADING 'Next Proficiency Test' SELECT (e.emp_fname ||' '|| e.emp_lname) Pilot, p.pil_pt135_date FROM hartmar.employee e join hartmar.pilot p on e.emp_num = p.emp_num WHERE p.pil_pt135_date < (CURRENT_DATE - 180) IF p.pil_pt135_date < (CURRENT_DATE - 180) THEN req_pt135_date = 'OVERDUE' ELSE req_pt135_date = DATEADD(mm,6,p.pil_pt135_date) ;
So I tried to use IF ELSE but I don't think I used it right because I get an error. Not even sure if this is close:
Code:
TTITLE 'RobAir - Pilot Proficiency Test Status' COLUMN pil_pt135_date - HEADING 'Last Proficiency Test' COLUMN req_pt135_date - HEADING 'Next Proficiency Test' SELECT (e.emp_fname ||' '|| e.emp_lname) Pilot, p.pil_pt135_date FROM hartmar.employee e join hartmar.pilot p on e.emp_num = p.emp_num WHERE p.pil_pt135_date < (CURRENT_DATE - 180) IF p.pil_pt135_date < (CURRENT_DATE - 180) THEN req_pt135_date = 'OVERDUE' ELSE req_pt135_date = DATEADD(mm,6,p.pil_pt135_date) ;
Why are you trying to get it to print 'overdue' if that wasn't part of the original task?


