Rolling totals query ~ please help
I have been stuck on a query for the last week. It would be amazing if someone could help me with this. nothing I have done has worked so far. I did post something a few days ago and was helped a bit but it just didnt work out the way I needed. This has been the hardest query I have ever worked on.
Im using oracle 11g.
What I am trying to do is get a bunch of running aggregate values based on dates of multiple projects.
I have did an export of the ddl for the actual table and records, I did not want to just post a sample of the data as it includes many records and I think it might actually be easier to have the full extract.
here is the link to the file http://santoro.us/pl_insert.sql
In the table I have IPS (which is a project id), create date, complete date, logged_date, status, due date (these are all the important columns)
What I am trying to get as an end result is 1 table or 1 view that has all the running totals per month for each project.
Here are the totals im looking to get
Open
Closed
open late
closed late
open on time closed on time
The thing is I need to start the months per project from the first month the project has a record. So if a projects first record starts on jan 1 2010 thats when the first record with totals should be, 01/2010 , then 02/2010, 03/2010, etc..until the current month. This has to be done per project.
so for example lets say there are only 2 projects (there are many more).
IPS 123
first record starts 01/01/2010
IPS 456
first record starts 01/01/2011
each have records that open and close on different dates in different months. some might be late (complete date > due date), some closed on time (complete date <= due date).
end result would be a table that has :
Date | IPS | open | closed | open late | closed late | open on time | closed on time |
01/2010 | 123 | 1 | 0 | etc..
months would go all the way to current month
then start proj 2
01/2011 | 456 | 1 | 0 | etc..
months would go all the way to current month
each record would be counted starting the create date of the record. As the records get late or closed (based on due date and complete date) then need to be added/removed from the running totals of the data.
This all has to be in 1 table or view. I know some people might say this is wrong way to do it but thats how it has to be done for the project im working on. Im generating xml at the end so the developer needs it like this.
Again thank you for any help and please let me know if you need any other information.
thank you.
Frank. No problem. that is great that it doesnt need ad hoc tables and could be done in pure sql. As I said this is the hardest query i have ever worked on. If you could help i would be greatful. I realize this forum is priceless resource and has helped me many times.
Please let me know if I should post anything else.
I am having a hard time understanding how I would dispaly each month with the aggregrated rolling totals from start month to current month for each project.
Im using oracle 11.2.3.3.0
CREATE TABLE "THERM_PUNCHLIST"
( "ENTRY_ID" VARCHAR2(50 BYTE),
"BATCH_DATE" DATE,
"IPS" VARCHAR2(50 BYTE),
"STATUS" VARCHAR2(20 BYTE),
"DUE_DATE" DATE,
"UNIT_SERIAL" VARCHAR2(500 BYTE),
"CREATE_DATE" DATE,
"COMPLETE_DATE" DATE,
"DB_LOGGED_DATE" DATE,
"REPORTED_DATE" DATE
--im posting more than 20 inserts as i want to be sure to get a few projects. the full ddl is at the link above with all projects and records
Insert into THERM_PUNCHLIST (ENTRY_ID,BATCH_DATE,IPS,STATUS,DUE_DATE,UNIT_SERIAL,CREATE_DATE,COMPLETE_DATE,DB_LOGGED_DATE,REPORTED_DATE) values ('1788788396',to_date('28-JAN-14','DD-MON-RR'),'102869','Closed',to_date('27-MAY-11','DD-MON-RR'),null,to_date('12-JUN-08','DD-MON-RR'),to_date('28-MAY-09','DD-MON-RR'),to_date('23-AUG-10','DD-MON-RR'),to_date('12-JUN-08','DD-MON-RR'));
Insert into THERM_PUNCHLIST (ENTRY_ID,BATCH_DATE,IPS,STATUS,DUE_DATE,UNIT_SERIAL,CREATE_DATE,COMPLETE_DATE,DB_LOGGED_DATE,REPORTED_DATE) values ('1788788387',to_date('28-JAN-14','DD-MON-RR'),'102869','Closed',to_date('27-MAY-11','DD-MON-RR'),null,to_date('12-JUN-08','DD-MON-RR'),to_date('28-MAY-09','DD-MON-RR'),to_date('23-AUG-10','DD-MON-RR'),to_date('12-JUN-08','DD-MON-RR'));
Insert into THERM_PUNCHLIST (ENTRY_ID,BATCH_DATE,IPS,STATUS,DUE_DATE,UNIT_SERIAL,CREATE_DATE,COMPLETE_DATE,DB_LOGGED_DATE,REPORTED_DATE) values ('1788788391',to_date('28-JAN-14','DD-MON-RR'),'102869','Closed',to_date('27-MAY-11','DD-MON-RR'),null,to_date('12-JUN-08','DD-MON-RR'),to_date('28-MAY-09','DD-MON-RR'),to_date('23-AUG-10','DD-MON-RR'),to_date('12-JUN-08','DD-MON-RR'));
Insert into THERM_PUNCHLIST (ENTRY_ID,BATCH_DATE,IPS,STATUS,DUE_DATE,UNIT_SERIAL,CREATE_DATE,COMPLETE_DATE,DB_LOGGED_DATE,REPORTED_DATE) values ('1788788372',to_date('28-JAN-14','DD-MON-RR'),'102869','Closed',to_date('27-MAY-11','DD-MON-RR'),null,to_date('12-JUN-08','DD-MON-RR'),to_date('28-MAY-09','DD-MON-RR'),to_date('23-AUG-10','DD-MON-RR'),to_date('12-JUN-08','DD-MON-RR'));
Insert into THERM_PUNCHLIST (ENTRY_ID,BATCH_DATE,IPS,STATUS,DUE_DATE,UNIT_SERIAL,CREATE_DATE,COMPLETE_DATE,DB_LOGGED_DATE,REPORTED_DATE) values ('1788788375',to_date('28-JAN-14','DD-MON-RR'),'102869','Closed',to_date('27-MAY-11','DD-MON-RR'),null,to_date('12-JUN-08','DD-MON-RR'),to_date('28-MAY-09','DD-MON-RR'),to_date('23-AUG-10','DD-MON-RR'),to_date('12-JUN-08','DD-MON-RR'));
Insert into THERM_PUNCHLIST (ENTRY_ID,BATCH_DATE,IPS,STATUS,DUE_DATE,UNIT_SERIAL,CREATE_DATE,COMPLETE_DATE,DB_LOGGED_DATE,REPORTED_DATE) values ('1788788385',to_date('28-JAN-14','DD-MON-RR'),'102869','Closed',to_date('27-MAY-11','DD-MON-RR'),null,to_date('12-JUN-08','DD-MON-RR'),to_date('28-MAY-09','DD-MON-RR'),to_date('23-AUG-10','DD-MON-RR'),to_date('12-JUN-08','DD-MON-RR'));
Insert into THERM_PUNCHLIST (ENTRY_ID,BATCH_DATE,IPS,STATUS,DUE_DATE,UNIT_SERIAL,CREATE_DATE,COMPLETE_DATE,DB_LOGGED_DATE,REPORTED_DATE) values ('1788788356',to_date('28-JAN-14','DD-MON-RR'),'102869','Closed',to_date('27-MAY-11','DD-MON-RR'),null,to_date('12-JUN-08','DD-MON-RR'),to_date('28-MAY-09','DD-MON-RR'),to_date('23-AUG-10','DD-MON-RR'),to_date('12-JUN-08','DD-MON-RR'));
Insert into THERM_PUNCHLIST (ENTRY_ID,BATCH_DATE,IPS,STATUS,DUE_DATE,UNIT_SERIAL,CREATE_DATE,COMPLETE_DATE,DB_LOGGED_DATE,REPORTED_DATE) values ('1788788360',to_date('28-JAN-14','DD-MON-RR'),'102869','Closed',to_date('27-MAY-11','DD-MON-RR'),null,to_date('12-JUN-08','DD-MON-RR'),to_date('28-MAY-09','DD-MON-RR'),to_date('23-AUG-10','DD-MON-RR'),to_date('12-JUN-08','DD-MON-RR'));
Insert into THERM_PUNCHLIST (ENTRY_ID,BATCH_DATE,IPS,STATUS,DUE_DATE,UNIT_SERIAL,CREATE_DATE,COMPLETE_DATE,DB_LOGGED_DATE,REPORTED_DATE) values ('1788788338',to_date('28-JAN-14','DD-MON-RR'),'102869','Closed',to_date('26-JAN-11','DD-MON-RR'),null,to_date('25-JUN-08','DD-MON-RR'),to_date('28-MAY-09','DD-MON-RR'),to_date('23-AUG-10','DD-MON-RR'),to_date('25-JUN-08','DD-MON-RR'));
Insert into THERM_PUNCHLIST (ENTRY_ID,BATCH_DATE,IPS,STATUS,DUE_DATE,UNIT_SERIAL,CREATE_DATE,COMPLETE_DATE,DB_LOGGED_DATE,REPORTED_DATE) values ('1788788317',to_date('28-JAN-14','DD-MON-RR'),'102869','Closed',to_date('26-JAN-11','DD-MON-RR'),null,to_date('29-JUN-08','DD-MON-RR'),to_date('28-MAY-09','DD-MON-RR'),to_date('23-AUG-10','DD-MON-RR'),to_date('29-JUN-08','DD-MON-RR'));
Insert into THERM_PUNCHLIST (ENTRY_ID,BATCH_DATE,IPS,STATUS,DUE_DATE,UNIT_SERIAL,CREATE_DATE,COMPLETE_DATE,DB_LOGGED_DATE,REPORTED_DATE) values ('2305623588',to_date('28-JAN-14','DD-MON-RR'),'505587','Closed',to_date('31-JAN-11','DD-MON-RR'),'875032 / 875034',to_date('09-JUN-10','DD-MON-RR'),to_date('08-JUL-10','DD-MON-RR'),to_date('02-MAR-11','DD-MON-RR'),to_date('09-JUN-10','DD-MON-RR'));
Insert into THERM_PUNCHLIST (ENTRY_ID,BATCH_DATE,IPS,STATUS,DUE_DATE,UNIT_SERIAL,CREATE_DATE,COMPLETE_DATE,DB_LOGGED_DATE,REPORTED_DATE) values ('4073131813',to_date('28-JAN-14','DD-MON-RR'),'504984','Closed',to_date('15-MAY-12','DD-MON-RR'),'E0839',to_date('17-FEB-12','DD-MON-RR'),to_date('31-MAR-12','DD-MON-RR'),to_date('18-APR-12','DD-MON-RR'),to_date('12-DEC-11','DD-MON-RR'));
Insert into THERM_PUNCHLIST (ENTRY_ID,BATCH_DATE,IPS,STATUS,DUE_DATE,UNIT_SERIAL,CREATE_DATE,COMPLETE_DATE,DB_LOGGED_DATE,REPORTED_DATE) values ('2305592103',to_date('28-JAN-14','DD-MON-RR'),'505587','Closed',to_date('31-JAN-11','DD-MON-RR'),'875032 / 875034',to_date('08-JAN-10','DD-MON-RR'),to_date('23-JUL-10','DD-MON-RR'),to_date('02-MAR-11','DD-MON-RR'),to_date('08-JAN-10','DD-MON-RR'));
Insert into THERM_PUNCHLIST (ENTRY_ID,BATCH_DATE,IPS,STATUS,DUE_DATE,UNIT_SERIAL,CREATE_DATE,COMPLETE_DATE,DB_LOGGED_DATE,REPORTED_DATE) values ('2305592105',to_date('28-JAN-14','DD-MON-RR'),'505587','Closed',to_date('31-JAN-11','DD-MON-RR'),'875032 / 875034',to_date('08-JAN-10','DD-MON-RR'),to_date('12-JUL-10','DD-MON-RR'),to_date('02-MAR-11','DD-MON-RR'),to_date('08-JAN-10','DD-MON-RR'));
Insert into THERM_PUNCHLIST (ENTRY_ID,BATCH_DATE,IPS,STATUS,DUE_DATE,UNIT_SERIAL,CREATE_DATE,COMPLETE_DATE,DB_LOGGED_DATE,REPORTED_DATE) values ('2305592108',to_date('28-JAN-14','DD-MON-RR'),'505587','Closed',to_date('31-JAN-11','DD-MON-RR'),'875032 / 875034',to_date('08-JAN-10','DD-MON-RR'),to_date('12-JUL-10','DD-MON-RR'),to_date('02-MAR-11','DD-MON-RR'),to_date('08-JAN-10','DD-MON-RR'));
Insert into THERM_PUNCHLIST (ENTRY_ID,BATCH_DATE,IPS,STATUS,DUE_DATE,UNIT_SERIAL,CREATE_DATE,COMPLETE_DATE,DB_LOGGED_DATE,REPORTED_DATE) values ('2305592101',to_date('28-JAN-14','DD-MON-RR'),'505587','Closed',to_date('31-JAN-11','DD-MON-RR'),'875032 / 875034',to_date('08-JAN-10','DD-MON-RR'),to_date('12-JUL-10','DD-MON-RR'),to_date('02-MAR-11','DD-MON-RR'),to_date('08-JAN-10','DD-MON-RR'));
Insert into THERM_PUNCHLIST (ENTRY_ID,BATCH_DATE,IPS,STATUS,DUE_DATE,UNIT_SERIAL,CREATE_DATE,COMPLETE_DATE,DB_LOGGED_DATE,REPORTED_DATE) values ('2305592087',to_date('28-JAN-14','DD-MON-RR'),'505587','Closed',to_date('31-JAN-11','DD-MON-RR'),'875032 / 875034',to_date('08-JAN-10','DD-MON-RR'),to_date('12-JUL-10','DD-MON-RR'),to_date('02-MAR-11','DD-MON-RR'),to_date('08-JAN-10','DD-MON-RR'));
Insert into THERM_PUNCHLIST (ENTRY_ID,BATCH_DATE,IPS,STATUS,DUE_DATE,UNIT_SERIAL,CREATE_DATE,COMPLETE_DATE,DB_LOGGED_DATE,REPORTED_DATE) values ('2305592096',to_date('28-JAN-14','DD-MON-RR'),'505587','Closed',to_date('31-JAN-11','DD-MON-RR'),'875032 / 875034',to_date('08-JAN-10','DD-MON-RR'),to_date('12-JUL-10','DD-MON-RR'),to_date('02-MAR-11','DD-MON-RR'),to_date('08-JAN-10','DD-MON-RR'));
Insert into THERM_PUNCHLIST (ENTRY_ID,BATCH_DATE,IPS,STATUS,DUE_DATE,UNIT_SERIAL,CREATE_DATE,COMPLETE_DATE,DB_LOGGED_DATE,REPORTED_DATE) values ('2305592099',to_date('28-JAN-14','DD-MON-RR'),'505587','Closed',to_date('31-JAN-11','DD-MON-RR'),'875032 / 875034',to_date('08-JAN-10','DD-MON-RR'),to_date('12-JUL-10','DD-MON-RR'),to_date('02-MAR-11','DD-MON-RR'),to_date('08-JAN-10','DD-MON-RR'));
Insert into THERM_PUNCHLIST (ENTRY_ID,BATCH_DATE,IPS,STATUS,DUE_DATE,UNIT_SERIAL,CREATE_DATE,COMPLETE_DATE,DB_LOGGED_DATE,REPORTED_DATE) values ('3652122705',to_date('28-JAN-14','DD-MON-RR'),'704145','Closed',to_date('01-SEP-10','DD-MON-RR'),null,to_date('13-JUN-10','DD-MON-RR'),to_date('25-APR-11','DD-MON-RR'),to_date('07-FEB-12','DD-MON-RR'),to_date('13-JUN-10','DD-MON-RR'));
Insert into THERM_PUNCHLIST (ENTRY_ID,BATCH_DATE,IPS,STATUS,DUE_DATE,UNIT_SERIAL,CREATE_DATE,COMPLETE_DATE,DB_LOGGED_DATE,REPORTED_DATE) values ('3652122696',to_date('28-JAN-14','DD-MON-RR'),'704145','Closed',to_date('01-SEP-10','DD-MON-RR'),null,to_date('13-JUN-10','DD-MON-RR'),to_date('25-APR-11','DD-MON-RR'),to_date('07-FEB-12','DD-MON-RR'),to_date('13-JUN-10','DD-MON-RR'));
Insert into THERM_PUNCHLIST (ENTRY_ID,BATCH_DATE,IPS,STATUS,DUE_DATE,UNIT_SERIAL,CREATE_DATE,COMPLETE_DATE,DB_LOGGED_DATE,REPORTED_DATE) values ('3652122693',to_date('28-JAN-14','DD-MON-RR'),'704145','Closed',to_date('01-SEP-10','DD-MON-RR'),null,to_date('13-JUN-10','DD-MON-RR'),to_date('25-APR-11','DD-MON-RR'),to_date('07-FEB-12','DD-MON-RR'),to_date('13-JUN-10','DD-MON-RR'));
Insert into THERM_PUNCHLIST (ENTRY_ID,BATCH_DATE,IPS,STATUS,DUE_DATE,UNIT_SERIAL,CREATE_DATE,COMPLETE_DATE,DB_LOGGED_DATE,REPORTED_DATE) values ('4904513300',to_date('28-JAN-14','DD-MON-RR'),'708829','Closed',to_date('04-OCT-12','DD-MON-RR'),'890273',to_date('04-JUL-12','DD-MON-RR'),to_date('09-APR-12','DD-MON-RR'),to_date('05-SEP-12','DD-MON-RR'),to_date('04-JUL-12','DD-MON-RR'));
Insert into THERM_PUNCHLIST (ENTRY_ID,BATCH_DATE,IPS,STATUS,DUE_DATE,UNIT_SERIAL,CREATE_DATE,COMPLETE_DATE,DB_LOGGED_DATE,REPORTED_DATE) values ('1785374403',to_date('28-JAN-14','DD-MON-RR'),'504865','Closed',to_date('31-DEC-10','DD-MON-RR'),null,to_date('20-JAN-10','DD-MON-RR'),to_date('19-FEB-11','DD-MON-RR'),to_date('20-AUG-10','DD-MON-RR'),to_date('20-JAN-10','DD-MON-RR'));
Insert into THERM_PUNCHLIST (ENTRY_ID,BATCH_DATE,IPS,STATUS,DUE_DATE,UNIT_SERIAL,CREATE_DATE,COMPLETE_DATE,DB_LOGGED_DATE,REPORTED_DATE) values ('1785375257',to_date('28-JAN-14','DD-MON-RR'),'504865','Closed',to_date('31-DEC-10','DD-MON-RR'),null,to_date('20-JAN-10','DD-MON-RR'),to_date('19-FEB-11','DD-MON-RR'),to_date('20-AUG-10','DD-MON-RR'),to_date('20-JAN-10','DD-MON-RR'));
Insert into THERM_PUNCHLIST (ENTRY_ID,BATCH_DATE,IPS,STATUS,DUE_DATE,UNIT_SERIAL,CREATE_DATE,COMPLETE_DATE,DB_LOGGED_DATE,REPORTED_DATE) values ('1785377988',to_date('28-JAN-14','DD-MON-RR'),'504865','Closed',to_date('31-DEC-10','DD-MON-RR'),null,to_date('20-JAN-10','DD-MON-RR'),to_date('07-JUN-11','DD-MON-RR'),to_date('20-AUG-10','DD-MON-RR'),to_date('20-JAN-10','DD-MON-RR'));
Insert into THERM_PUNCHLIST (ENTRY_ID,BATCH_DATE,IPS,STATUS,DUE_DATE,UNIT_SERIAL,CREATE_DATE,COMPLETE_DATE,DB_LOGGED_DATE,REPORTED_DATE) values ('2249843931',to_date('28-JAN-14','DD-MON-RR'),'701402','Closed',to_date('20-JUN-11','DD-MON-RR'),null,to_date('11-OCT-10','DD-MON-RR'),to_date('02-APR-11','DD-MON-RR'),to_date('10-FEB-11','DD-MON-RR'),to_date('11-OCT-10','DD-MON-RR'));
Insert into THERM_PUNCHLIST (ENTRY_ID,BATCH_DATE,IPS,STATUS,DUE_DATE,UNIT_SERIAL,CREATE_DATE,COMPLETE_DATE,DB_LOGGED_DATE,REPORTED_DATE) values ('1785384765',to_date('28-JAN-14','DD-MON-RR'),'504865','Closed',to_date('31-DEC-10','DD-MON-RR'),null,to_date('20-JAN-10','DD-MON-RR'),to_date('07-JUN-11','DD-MON-RR'),to_date('20-AUG-10','DD-MON-RR'),to_date('20-JAN-10','DD-MON-RR'));
Insert into THERM_PUNCHLIST (ENTRY_ID,BATCH_DATE,IPS,STATUS,DUE_DATE,UNIT_SERIAL,CREATE_DATE,COMPLETE_DATE,DB_LOGGED_DATE,REPORTED_DATE) values ('1785385084',to_date('28-JAN-14','DD-MON-RR'),'504865','Closed',to_date('31-DEC-10','DD-MON-RR'),null,to_date('20-JAN-10','DD-MON-RR'),to_date('07-JUN-11','DD-MON-RR'),to_date('20-AUG-10','DD-MON-RR'),to_date('20-JAN-10','DD-MON-RR'));
Insert into THERM_PUNCHLIST (ENTRY_ID,BATCH_DATE,IPS,STATUS,DUE_DATE,UNIT_SERIAL,CREATE_DATE,COMPLETE_DATE,DB_LOGGED_DATE,REPORTED_DATE) values ('1785388821',to_date('28-JAN-14','DD-MON-RR'),'504865','Closed',to_date('31-DEC-10','DD-MON-RR'),null,to_date('20-JAN-10','DD-MON-RR'),to_date('07-JUN-11','DD-MON-RR'),to_date('20-AUG-10','DD-MON-RR'),to_date('20-JAN-10','DD-MON-RR'));
Insert into THERM_PUNCHLIST (ENTRY_ID,BATCH_DATE,IPS,STATUS,DUE_DATE,UNIT_SERIAL,CREATE_DATE,COMPLETE_DATE,DB_LOGGED_DATE,REPORTED_DATE) values ('1785388837',to_date('28-JAN-14','DD-MON-RR'),'504865','Closed',to_date('31-DEC-10','DD-MON-RR'),null,to_date('20-JAN-10','DD-MON-RR'),to_date('07-JUN-11','DD-MON-RR'),to_date('20-AUG-10','DD-MON-RR'),to_date('20-JAN-10','DD-MON-RR'));
Insert into THERM_PUNCHLIST (ENTRY_ID,BATCH_DATE,IPS,STATUS,DUE_DATE,UNIT_SERIAL,CREATE_DATE,COMPLETE_DATE,DB_LOGGED_DATE,REPORTED_DATE) values ('1785393519',to_date('28-JAN-14','DD-MON-RR'),'504865','Closed',to_date('31-MAR-12','DD-MON-RR'),null,to_date('20-JAN-10','DD-MON-RR'),to_date('28-FEB-12','DD-MON-RR'),to_date('20-AUG-10','DD-MON-RR'),to_date('20-JAN-10','DD-MON-RR'));
Insert into THERM_PUNCHLIST (ENTRY_ID,BATCH_DATE,IPS,STATUS,DUE_DATE,UNIT_SERIAL,CREATE_DATE,COMPLETE_DATE,DB_LOGGED_DATE,REPORTED_DATE) values ('1785393585',to_date('28-JAN-14','DD-MON-RR'),'504865','Closed',to_date('31-MAR-12','DD-MON-RR'),null,to_date('20-JAN-10','DD-MON-RR'),to_date('28-FEB-12','DD-MON-RR'),to_date('20-AUG-10','DD-MON-RR'),to_date('20-JAN-10','DD-MON-RR'));
Insert into THERM_PUNCHLIST (ENTRY_ID,BATCH_DATE,IPS,STATUS,DUE_DATE,UNIT_SERIAL,CREATE_DATE,COMPLETE_DATE,DB_LOGGED_DATE,REPORTED_DATE) values ('1785375310',to_date('28-JAN-14','DD-MON-RR'),'504865','Closed',to_date('31-DEC-10','DD-MON-RR'),null,to_date('20-JAN-10','DD-MON-RR'),to_date('07-JUN-11','DD-MON-RR'),to_date('20-AUG-10','DD-MON-RR'),to_date('20-JAN-10','DD-MON-RR'));
Insert into THERM_PUNCHLIST (ENTRY_ID,BATCH_DATE,IPS,STATUS,DUE_DATE,UNIT_SERIAL,CREATE_DATE,COMPLETE_DATE,DB_LOGGED_DATE,REPORTED_DATE) values ('1785375318',to_date('28-JAN-14','DD-MON-RR'),'504865','Closed',to_date('31-DEC-10','DD-MON-RR'),null,to_date('20-JAN-10','DD-MON-RR'),to_date('07-JUN-11','DD-MON-RR'),to_date('20-AUG-10','DD-MON-RR'),to_date('20-JAN-10','DD-MON-RR'));
Insert into THERM_PUNCHLIST (ENTRY_ID,BATCH_DATE,IPS,STATUS,DUE_DATE,UNIT_SERIAL,CREATE_DATE,COMPLETE_DATE,DB_LOGGED_DATE,REPORTED_DATE) values ('1785375324',to_date('28-JAN-14','DD-MON-RR'),'504865','Closed',to_date('31-DEC-10','DD-MON-RR'),null,to_date('20-JAN-10','DD-MON-RR'),to_date('07-JUN-11','DD-MON-RR'),to_date('20-AUG-10','DD-MON-RR'),to_date('20-JAN-10','DD-MON-RR'));
Insert into THERM_PUNCHLIST (ENTRY_ID,BATCH_DATE,IPS,STATUS,DUE_DATE,UNIT_SERIAL,CREATE_DATE,COMPLETE_DATE,DB_LOGGED_DATE,REPORTED_DATE) values ('1785378644',to_date('28-JAN-14','DD-MON-RR'),'504865','Closed',to_date('31-DEC-10','DD-MON-RR'),null,to_date('20-JAN-10','DD-MON-RR'),to_date('07-JUN-11','DD-MON-RR'),to_date('20-AUG-10','DD-MON-RR'),to_date('20-JAN-10','DD-MON-RR'));
Insert into THERM_PUNCHLIST (ENTRY_ID,BATCH_DATE,IPS,STATUS,DUE_DATE,UNIT_SERIAL,CREATE_DATE,COMPLETE_DATE,DB_LOGGED_DATE,REPORTED_DATE) values ('1785382711',to_date('28-JAN-14','DD-MON-RR'),'504865','Closed',to_date('31-DEC-10','DD-MON-RR'),null,to_date('20-JAN-10','DD-MON-RR'),to_date('07-JUN-11','DD-MON-RR'),to_date('20-AUG-10','DD-MON-RR'),to_date('20-JAN-10','DD-MON-RR'));
Insert into THERM_PUNCHLIST (ENTRY_ID,BATCH_DATE,IPS,STATUS,DUE_DATE,UNIT_SERIAL,CREATE_DATE,COMPLETE_DATE,DB_LOGGED_DATE,REPORTED_DATE) values ('2249843992',to_date('28-JAN-14','DD-MON-RR'),'701402','Closed',to_date('20-JUN-11','DD-MON-RR'),null,to_date('20-AUG-10','DD-MON-RR'),to_date('28-JAN-11','DD-MON-RR'),to_date('10-FEB-11','DD-MON-RR'),to_date('20-AUG-10','DD-MON-RR'));
Insert into THERM_PUNCHLIST (ENTRY_ID,BATCH_DATE,IPS,STATUS,DUE_DATE,UNIT_SERIAL,CREATE_DATE,COMPLETE_DATE,DB_LOGGED_DATE,REPORTED_DATE) values ('2249843996',to_date('28-JAN-14','DD-MON-RR'),'701402','Closed',to_date('20-JUN-11','DD-MON-RR'),null,to_date('20-AUG-10','DD-MON-RR'),to_date('23-FEB-11','DD-MON-RR'),to_date('10-FEB-11','DD-MON-RR'),to_date('20-AUG-10','DD-MON-RR'));
Insert into THERM_PUNCHLIST (ENTRY_ID,BATCH_DATE,IPS,STATUS,DUE_DATE,UNIT_SERIAL,CREATE_DATE,COMPLETE_DATE,DB_LOGGED_DATE,REPORTED_DATE) values ('2249844002',to_date('28-JAN-14','DD-MON-RR'),'701402','Closed',to_date('20-JUN-11','DD-MON-RR'),null,to_date('14-MAY-10','DD-MON-RR'),to_date('01-FEB-11','DD-MON-RR'),to_date('10-FEB-11','DD-MON-RR'),to_date('14-MAY-10','DD-MON-RR'));
Insert into THERM_PUNCHLIST (ENTRY_ID,BATCH_DATE,IPS,STATUS,DUE_DATE,UNIT_SERIAL,CREATE_DATE,COMPLETE_DATE,DB_LOGGED_DATE,REPORTED_DATE) values ('2249843984',to_date('28-JAN-14','DD-MON-RR'),'701402','Closed',to_date('20-JUN-11','DD-MON-RR'),null,to_date('20-AUG-10','DD-MON-RR'),to_date('03-JUN-11','DD-MON-RR'),to_date('10-FEB-11','DD-MON-RR'),to_date('20-AUG-10','DD-MON-RR'));
Insert into THERM_PUNCHLIST (ENTRY_ID,BATCH_DATE,IPS,STATUS,DUE_DATE,UNIT_SERIAL,CREATE_DATE,COMPLETE_DATE,DB_LOGGED_DATE,REPORTED_DATE) values ('2249843968',to_date('28-JAN-14','DD-MON-RR'),'701402','Closed',to_date('20-JUN-11','DD-MON-RR'),null,to_date('10-SEP-10','DD-MON-RR'),to_date('14-JAN-11','DD-MON-RR'),to_date('10-FEB-11','DD-MON-RR'),to_date('10-SEP-10','DD-MON-RR'));
Insert into THERM_PUNCHLIST (ENTRY_ID,BATCH_DATE,IPS,STATUS,DUE_DATE,UNIT_SERIAL,CREATE_DATE,COMPLETE_DATE,DB_LOGGED_DATE,REPORTED_DATE) values ('2249843921',to_date('28-JAN-14','DD-MON-RR'),'701402','Closed',to_date('20-JUN-11','DD-MON-RR'),null,to_date('20-AUG-10','DD-MON-RR'),to_date('28-JAN-11','DD-MON-RR'),to_date('10-FEB-11','DD-MON-RR'),to_date('20-AUG-10','DD-MON-RR'));
Insert into THERM_PUNCHLIST (ENTRY_ID,BATCH_DATE,IPS,STATUS,DUE_DATE,UNIT_SERIAL,CREATE_DATE,COMPLETE_DATE,DB_LOGGED_DATE,REPORTED_DATE) values ('2249843913',to_date('28-JAN-14','DD-MON-RR'),'701402','Closed',to_date('20-JUN-11','DD-MON-RR'),null,to_date('20-AUG-10','DD-MON-RR'),to_date('10-FEB-11','DD-MON-RR'),to_date('10-FEB-11','DD-MON-RR'),to_date('20-AUG-10','DD-MON-RR'));
Insert into THERM_PUNCHLIST (ENTRY_ID,BATCH_DATE,IPS,STATUS,DUE_DATE,UNIT_SERIAL,CREATE_DATE,COMPLETE_DATE,DB_LOGGED_DATE,REPORTED_DATE) values ('2249843897',to_date('28-JAN-14','DD-MON-RR'),'701402','Closed',to_date('20-JUN-11','DD-MON-RR'),null,to_date('20-AUG-10','DD-MON-RR'),to_date('03-JUN-11','DD-MON-RR'),to_date('10-FEB-11','DD-MON-RR'),to_date('20-AUG-10','DD-MON-RR'));
Similar Messages
-
How to improve the performance of the attached query, Please help
Hi,
How to improve performance of the below query, Please help. also attached explain plan -
SELECT Camp.Id,
rCam.AccountKey,
Camp.Id,
CamBilling.Cpm,
CamBilling.Cpc,
CamBilling.FlatRate,
Camp.CampaignKey,
Camp.AccountKey,
CamBilling.billoncontractedamount,
(SUM(rCam.Impressions) * 0.001 + SUM(rCam.Clickthrus)) AS GR,
rCam.AccountKey as AccountKey
FROM Campaign Camp, rCamSit rCam, CamBilling, Site xSite
WHERE Camp.AccountKey = rCam.AccountKey
AND Camp.AvCampaignKey = rCam.AvCampaignKey
AND Camp.AccountKey = CamBilling.AccountKey
AND Camp.CampaignKey = CamBilling.CampaignKey
AND rCam.AccountKey = xSite.AccountKey
AND rCam.AvSiteKey = xSite.AvSiteKey
AND rCam.RmWhen BETWEEN to_date('01-01-2009', 'DD-MM-YYYY') and
to_date('01-01-2011', 'DD-MM-YYYY')
GROUP By rCam.AccountKey,
Camp.Id,
CamBilling.Cpm,
CamBilling.Cpc,
CamBilling.FlatRate,
Camp.CampaignKey,
Camp.AccountKey,
CamBilling.billoncontractedamount
Explain Plan :-
Description Object_owner Object_name Cost Cardinality Bytes
SELECT STATEMENT, GOAL = ALL_ROWS 14 1 13
SORT AGGREGATE 1 13
VIEW GEMINI_REPORTING 14 1 13
HASH GROUP BY 14 1 103
NESTED LOOPS 13 1 103
HASH JOIN 12 1 85
TABLE ACCESS BY INDEX ROWID GEMINI_REPORTING RCAMSIT 2 4 100
NESTED LOOPS 9 5 325
HASH JOIN 7 1 40
SORT UNIQUE 2 1 18
TABLE ACCESS BY INDEX ROWID GEMINI_PRIMARY SITE 2 1 18
INDEX RANGE SCAN GEMINI_PRIMARY SITE_I0 1 1
TABLE ACCESS FULL GEMINI_PRIMARY SITE 3 27 594
INDEX RANGE SCAN GEMINI_REPORTING RCAMSIT_I 1 1 5
TABLE ACCESS FULL GEMINI_PRIMARY CAMPAIGN 3 127 2540
TABLE ACCESS BY INDEX ROWID GEMINI_PRIMARY CAMBILLING 1 1 18
INDEX UNIQUE SCAN GEMINI_PRIMARY CAMBILLING_U1 0 1Hello,
This has really nothing to do with the Oracle Forms product.
Please, send the SQL or/and PL/SQL questions in the corresponding forums.
Francois -
hi, my ipad 2 won't charge nor sync but it can be charge when it totally drain. please help..
Hello Thisbemadi,
Thanks for using Apple Support Communities.
Please ensure you are charging your iPad with the Apple cable and power adapter that came with the device. If the issue persists, reset your iPad to its factory settings and try charging again.
iPad: Charging the battery
Use iTunes to restore your iOS device to factory settings
Take care,
Alex H. -
Pivot table query - PLEASE HELP
I have one requirement whichis similar like this.
I have following tables.
POSITIONS (one account holds multiple securities)
account_id security_id total
1 101 300
1 102 500
2 102 300
2 103 600
3 104 400
4 104 800
SECURITIES
security_id security_name country region
101 ABC USA NA
102 EFG USA NA
103 PQR GBR EUR
104 XYZ CANADA NA
I will get all the account numbers from front end application, for which I have to display output like this. For example I am getting accounts, 1,2,3 and 4 and have to display like columns at the end. I have to groupy by region and country.
REGION COUNTRY SECURITY_ID SECURITY_NAME 1 2 3 4
NA USA 101 ABC 300
102 EFG 500 300
COUNTRY TOTAL 800 300
CANADA 104 XYZ 400 800
REGION TOTAL 800 300 400 800
EUR GBR 103 PQR 600
COUNTRY TOTAL 600
REGION TOTAL 800 900 400 800
I am working on Oracle 9i Release 2 and front end is .net. Can anyone please help me out with a solution using a query or a stored proc. For Stored procedure, I should send refcurser as OUT parameter or any possible solution.
Thanks in advance.You could do the following:
In SQL
You can use the decode function and SUM over it.
Get the totals by region and country
select region,country, s.sec_id, sec_name,
sum(decode(acct_id,1,total,0)) a1,
sum(decode(acct_id,2,total,0)) a2,
sum(decode(acct_id,3,total,0)) a3,
sum(decode(acct_id,4,total,0)) a4
from positions p, securities s
where p.SEC_ID = s.SEC_ID
group by region,country, s.sec_id, sec_name
You can run similar sql to get totals by country or region separately ... just remove from select and group by clause the column name that you do not want to be displayed.
The limitation here is that you would need to write the decode statement for every account. Some programming may be needed here.
In PLSQL
create or replace procedure acct_sum (cr OUT sys_refcursor)
is
cursor c1 is
select distinct acct_id from positions order by 1 asc;
var1 varchar2(1000) := ' ';
var2 varchar2(1000);
begin
for i in c1 loop
var1 := var1 || ' sum(decode(acct_id, ' || i.acct_id || ', total,0) ),';
end loop;
var1 := substr(var1,1,length(var1)-1);
open cr for
'select region,country, s.sec_id, sec_name, ' || var1 ||
'from positions p, securities s
where p.SEC_ID = s.SEC_ID
group by region,country, s.sec_id, sec_name';
end acct_sum;
You may want to modify the code so pass in an array of accounts and loop through the content to get all the accounts.
Hope this helps
Shakti
http://www.impact-sol.com
Developers of Guggi Oracle - Tool for DBAs and Developers -
PROBLEM WITH HIERARCHICAL QUERY - PLEASE HELP
I have got three tables :
CREATE TABLE FIRM
(FID INTEGER NOT NULL PRIMARY KEY,
FNAME VARCHAR(40),
FTYPE VARCHAR(3),
MASTERID INTEGER );
CREATE TABLE FACULTY
(FAID INTEGER NOT NULL PRIMARY KEY,
FANAME VARCHAR(40),
FATYPE VARCHAR(3),
MASTERID INTEGER );
CREATE TABLE EMPLOYEE
(EID INTEGER NOT NULL PRIMARY KEY,
ENAME VARCHAR(20),
ESURNAME VARCHAR(20),
EJOB VARCHAR(3),
MASTERID INTEGER );
This is a hierarchical tree(or is ment to be, I,m complete rookie ) . Firm can be the root or can be slave to another firm. Faculty can be slave to firm, or to another faculty. Employee can be slave to faculty or to another employee(e.g. boss). This connections are specified by MASTERIDs.
I need to write a procedure, which parameter would be node ID. It is meant to create a VIEW from this node as if it was a root (view of a subtree).
I tried CONNECT BY clause but it works only on one table at a time and I have here three tables.
I completely don,t know how to write it. Please help.create view hierarchy as
select id, master_id, name from table1
union all
select id, master_id, name from table2
union all
select id, master_id, name from table3
Then do your connect by query against hierarchy.
It will not work in 8i (connect by on views not allowed), so you will need to materialize the view.
Kirill -
How to make recursive query.Please help
Dear Experts:
I want to retrieve all employees located in a department in addition to all other employees located in the child's nodes of this department too.
Problem Details:
I have "Employees" table and "Departments" Table
The structure of Dept Table is:
ID primary key
parent_dept foreign key(id)
deptname varchar2
deptType varchar2
The Employee table structure is
ID primary key
dept_id foreign key(Department.id)
empName varchar2Sample data for departments
ID : 1
parent_dept : null
deptname: General Manager office
deptType : 'GM'
ID :=2
parent_dept : 1
deptname: Information tech.
deptType : 'DPT'
ID :=3
parent_dept : 2
deptname: Software Development
deptType : 'SECTION'Sample Data for employees
ID : 101
dept_id :1
empName King
ID : 102
dept_id :2
empName ALAN
ID : 103
dept_id :2
empName SAM
ID : 104
dept_id :3
empName JANEI want to create a query that accepts a parameter "p_department_id" and returns All employees on the following conditions
1- In case the parameter value is null , then retrieve All Employees "king - alan- sam-jane"
2- In Case the parameter value is 1 , then retrieve all the employees under department id =1 in addition to all the employees located under the children departments.
in this case it will be "king - alan- sam-jane"
3- In case parameter value is 2 , then return all the employees under department id =2 in addition to all the employees located under the children departments.
In this case it will be " alan- sam-jane"
4- In case parameter value is 3 , then return all the employees under department id =3 in addition to all the employees located under the children departments.
in this case it will be only "JANE"
In brief , If I pass any value to the parameter :p_department_id , I want to retrieve all employees located in this department in addition to other employees located in the child's nodes of this department id
I use oracle database 11g release 2
Please help me
Thanks
Edited by: ta**** on Apr 3, 2013 5:56 PM
Edited by: ta**** on Apr 3, 2013 5:58 PMSQL> variable p_department_id number
SQL> exec :p_department_id := null
PL/SQL procedure successfully completed.
SQL> with employees as (
2 select 101 id,1 dept_id,'King' empName from dual union all
3 select 102,2,'ALAN' from dual union all
4 select 103,2,'SAM' from dual union all
5 select 104,3,'JANE' from dual
6 ),
7 departments as (
8 select 1 id,null parent_dept,'General Manager office' deptname,'GM' deptType from dual union all
9 select 2,1,'Information tech.','DPT' from dual union all
10 select 3,2,'Software Development','SECTION' from dual
11 )
12 select *
13 from employees
14 where dept_id in (
15 select id
16 from departments
17 start with (
18 (
19 :p_department_id is null
20 and
21 parent_dept is null
22 )
23 or
24 id = :p_department_id
25 )
26 connect by parent_dept = prior id
27 )
28 /
ID DEPT_ID EMPN
101 1 King
102 2 ALAN
103 2 SAM
104 3 JANE
SQL> exec :p_department_id := 1
PL/SQL procedure successfully completed.
SQL> /
ID DEPT_ID EMPN
101 1 King
102 2 ALAN
103 2 SAM
104 3 JANE
SQL> exec :p_department_id := 2
PL/SQL procedure successfully completed.
SQL> /
ID DEPT_ID EMPN
102 2 ALAN
103 2 SAM
104 3 JANE
SQL> exec :p_department_id := 3
PL/SQL procedure successfully completed.
SQL> /
ID DEPT_ID EMPN
104 3 JANE
SQL> SY. -
Table1
QTE_ID SEQ_NO
1435177 2
1435177 5
1435177 7
1435177 8
1435177 12
1435177 14
Table2
QTE_ID SEQ_NO CMMT_CURR_AMT
1435177 1 98500
1435177 2 98500
1435177 3 0
1435177 4 98500
1435177 5 98500
1435177 7 98500
1435177 8 98500
1435177 11 59300
1435177 12 59300
1435177 14 59300
The result should be
QTE_ID SEQ_NO CMMT_CURR_AMT
1435177 2 0 (where 0 = cmmt_curr_amt of seq 2 - cmmt_curr_amt of seq 1 from table 2)
1435177 5 0 (where 0 = cmmt_curr_amt of seq 5 - cmmt_curr_amt of seq 4 from table 2)
1435177 7 0 (where 0 = cmmt_curr_amt of seq 7 - cmmt_curr_amt of seq 5 from table 2)
1435177 8 0 (where 0 = cmmt_curr_amt of seq 8 - cmmt_curr_amt of seq 7 from table 2)
1435177 12 0 (where 0 = cmmt_curr_amt of seq 12 - cmmt_curr_amt of seq 11 from table 2)
1435177 14 0 (where 0 = cmmt_curr_amt of seq 14 - cmmt_curr_amt of seq 12 from table 2)
I have to get the difference of cmmt_curr_amt from the table2 from seq 14 to seq 12 for seq14 in table 1.
Please help me in writing the query.
Thanks in advance.
SrinivasWITH table1 AS
(SELECT 1435177 qte_id, 2 seq_no
FROM dual
UNION ALL
SELECT 1435177 qte_id, 5 seq_no
FROM dual
UNION ALL
SELECT 1435177 qte_id, 7 seq_no
FROM dual
UNION ALL
SELECT 1435177 qte_id, 8 seq_no
FROM dual
UNION ALL
SELECT 1435177 qte_id, 12 seq_no
FROM dual
UNION ALL
SELECT 1435177 qte_id, 14 seq_no
FROM dual
table2 AS
SELECT 1435177 qte_id, 1 seq_no, 98500 cmmt_curr_amt
FROM dual
UNION ALL
SELECT 1435177 qte_id, 2 seq_no, 98500 cmmt_curr_amt
FROM dual
UNION ALL
SELECT 1435177 qte_id, 3 seq_no, 0 cmmt_curr_amt
FROM dual
UNION ALL
SELECT 1435177 qte_id, 4 seq_no, 98500 cmmt_curr_amt
FROM dual
UNION ALL
SELECT 1435177 qte_id, 5 seq_no, 98500 cmmt_curr_amt
FROM dual
UNION ALL
SELECT 1435177 qte_id, 7 seq_no, 98500 cmmt_curr_amt
FROM dual
UNION ALL
SELECT 1435177 qte_id, 8 seq_no, 98500 cmmt_curr_amt
FROM dual
UNION ALL
SELECT 1435177 qte_id, 11 seq_no, 59300 cmmt_curr_amt
FROM dual
UNION ALL
SELECT 1435177 qte_id, 12 seq_no, 59300 cmmt_curr_amt
FROM dual
UNION ALL
SELECT 1435177 qte_id, 14 seq_no, 59300 cmmt_curr_amt
FROM dual
SELECT qte_id, t2_seq_no, cmmt_curr_amt - cmmt_curr_lag diff
FROM
(SELECT t2.qte_id, t2.seq_no t2_seq_no, t1.seq_no t1_seq_no, cmmt_curr_amt, LAG(cmmt_curr_amt,1,0) OVER (PARTITION BY t2.qte_id ORDER BY t2.seq_no) cmmt_curr_lag
FROM table1 t1, table2 t2
WHERE t2.qte_id = t1.qte_id (+)
AND t2.seq_no = t1.seq_no(+)
ORDER BY 1,2
WHERE t1_seq_no IS NOT NULL
ORDER BY 1,2
QTE_ID T2_SEQ_NO DIFF
1435177 2 0
1435177 5 0
1435177 7 0
1435177 8 0
1435177 12 0
1435177 14 0 -
How to rewrite this query without sub query please help me
Hello All Good Evening,
Could you please help me with this query, how can i write this query without sub query, or how can write this query another ways
please help me
select planno, status1, count(*) Counts from
select a.ValetNO PlanNo ,
case
when JoinCode in ('00', '01', '02') then 'Actcess'
when JoinCode in ('20', '21', '22', '23','38', '39') then
'Secured' else 'Other' end Status1 ---, COUNT (*)
from dbo.ppt a(NOLOCK) left join dbo.acts b on a.P_ID = b.P_ID and a.ValetNO = b.ValetNO
--group by a.ValetNO
a group by planno, status1
order by 2
Thank you in Advance
MilanWhats your objective here? Sorry, am not able to understand the reason for this change.
Try the below:(Not tested)
;With cte
As
select a.ValetNO PlanNo ,
case
when JoinCode in ('00', '01', '02') then 'Actcess'
when JoinCode in ('20', '21', '22', '23','38', '39') then
'Secured' else 'Other' end Status1 ---, COUNT (*)
from dbo.ppt a(NOLOCK) left join dbo.acts b on a.P_ID = b.P_ID and a.ValetNO = b.ValetNO
select planno, status1, count(*) Counts from cte
a group by planno, status1
order by 2
Even below:
select a.ValetNO PlanNo ,
case
when JoinCode in ('00', '01', '02') then 'Actcess'
when JoinCode in ('20', '21', '22', '23','38', '39') then
'Secured' else 'Other' end Status1 , COUNT (1)
from dbo.ppt a(NOLOCK) left join dbo.acts b on a.P_ID = b.P_ID and a.ValetNO = b.ValetNO
Group by a.ValetNO ,
case
when JoinCode in ('00', '01', '02') then 'Actcess'
when JoinCode in ('20', '21', '22', '23','38', '39') then
'Secured' else 'Other' end -
Problem while designing query please help
Hi all,
I have to query to find No of open cases, No of closed cases,
Average of open cases, Average age of closed cases,
Maximum of closed cases for a particulat Current assigne(char).
my desired output is as follows.
CurAssigne Noofopencases Noofclosed cases Avgage(opencases) Max(open)
CurAssigne1 10 20 8 9
CurAssigne1 18 22 9 10
My cube is consists of.
4 Dimensions & 4 key figures
4Dimensions are listed below.
Business Partner{currentassigne, previousassigne,acmanager}
createdon{createdonmonth,createdonday,createdtime}
closedon{closedmonth,closedday,closedtime}
Status{Latest case status-(2 status are available for each case - open,close)}
above the objects between {} are chars.
4 keys are listed below.
no of cases.
age
first response time
research time.
Please help me to design this query friends..
It's very urgent friends please help me.Hi,
Please share your system configuration on which you are trying to install Ps CS6.
Regards,
Ashutosh
Ps Installer QE -
Passing parameter to a SQL query - Please help
Hi All,
I am new to JDBC. I have been trying to pass an external variable to an SQL Query.
The query is
String username1="le";
PreparedStatement pstmt = null;
pstmt = c.prepareStatement("select * from users where USER_NAME like '%?%'");
pstmt.setString(1, username1);
pstmt.executeQuery();
ResultSet rs = pstmt.getResultSet();
I am trying to retrieve values from the users table where the USER_NAME column value that is a String contains the supplied value username1.
I am using the question mark (?) character to pass the value from the variable username1. I am also using the '%' substitution character which matches for any number of characters. So, the above query should retrieve rows where the USER_NAME is something like "charles","leander","Elena" etc.( that contains "le")
I am getting the error:
SQLException: java.sql.SQLException: ORA-01006: bind variable does not exist
I changed the query to
PreparedStatement pstmt = null;
pstmt = c.prepareStatement("select * from users where USER_NAME like '% " + username1 + "%'");
//pstmt.setString(1, username1);
pstmt.executeQuery();
This time , it is not giving the error and retrieving properly.
But I want to use the original query and use the "pstmt.setString(1, username1); " . Is there any way of achieving this?
Please help.
Cheers,
charles_amhi,
try this...
String username1="%le%";
pstmt = c.prepareStatement("select * from users where USER_NAME like ?")
pstmt.setString(1,username1);
cheers,
rpk -
Hi experts,
what i want to do is write a single query which will show whether a employee
exits in the company or not.I have two tables emp and dept.There are as follows.
SQL> select * from emp;
NAME DEPTNO EMPNO
xxx 10 33036
YYY 12 2345
ZZZ 13 678
KKK 14 5678
RRR 15 7865
SQL> select * from dept;
DEPTNO LOCATION
10 AAA
11 BBB
12 CCC
13 DDD
what i want is it will select records from the emp table and find whether corrosponding
deptno really exists in the dept table.If the value is found in deptno column the dept table then it will set the value
Y other wise it will be N and all i have to do with the help of a single query.
expected result
name empno exists
xxx 33036 Y
YYY 2345 Y
ZZZ 678 Y
KKK 5678 N
RRR 7865 N
Please help.
Regards
RajatSELECT EMPNO, NAME , EMPNO , NVL( ( SELECT 'Y' FROM DEPT WHERE EMP.DEPTNO=DEPT.DEPTNO),'N') EXIST
FROM EMP
ORDER BY 1
Demo
SQL> WITH EMP AS(
2 SELECT 'XXX' NAME , 10 DEPTNO ,33036 EMPNO FROM DUAL UNION
3 SELECT 'YYY', 12, 2345 FROM DUAL UNION
4 SELECT 'ZZZ', 13 ,678 FROM DUAL UNION
5 SELECT 'KKK', 14 ,5678 FROM DUAL UNION
6 SELECT 'RRR', 15 ,7865 FROM DUAL ),
7 DEPT AS(
8 SELECT 10 DEPTNO,'AAA' DNAME FROM DUAL UNION
9 SELECT 11 ,'BBB' FROM DUAL UNION
10 SELECT 12 ,'CCC' FROM DUAL UNION
11 SELECT 13 ,'DDD'FROM DUAL )
12 SELECT EMPNO, NAME , EMPNO , NVL( ( SELECT 'Y' FROM DEPT WHERE EMP.DEPTNO=DEPT.DEPTNO),'N')
EXIST
13 FROM EMP
14 ORDER BY 1
15 /
EMPNO NAM EMPNO E
678 ZZZ 678 Y
2345 YYY 2345 Y
5678 KKK 5678 N
7865 RRR 7865 N
33036 XXX 33036 Y
SQL> Edited by: Salim Chelabi on Dec 7, 2008 4:15 AM -
Hello Forum Members,
Can you please help me out:
SQL> select * from quarter_test4;
QUARTER CONFIG REP_DATE
Q1-2007 10 12-JAN-07
Q2-2007 10 21-APR-07
Q3-2007 870 14-AUG-07
Q4-2007 50 15-NOV-07
Q1-2008 60 02-JAN-09
Q4-2006 160 02-DEC-06
I want the following out put:
Please note that the future quarters should have current quarter sum(config).Please note that The current table
does not hold future quarters.I have to genarate query on which a report is based.
My Query:
SELECT quarter,
CASE
WHEN qtr > TRUNC(SYSDATE, 'q')
THEN LAST_VALUE(sum_config IGNORE NULLS) OVER(ORDER BY qtr)
ELSE sum_config
END sum_config
FROM (SELECT qtr, q.qtrstr quarter, SUM(qt.config) sum_config
FROM (SELECT 'Q' || TO_CHAR(qtr, 'q-yyyy') qtrstr, qtr
FROM (SELECT ADD_MONTHS(ADD_MONTHS(TRUNC(SYSDATE, 'q'), -13), 3 *(LEVEL - 1)) qtr
FROM DUAL
CONNECT BY LEVEL <= 9)
ORDER BY qtr) q,
quarter_test4 qt
WHERE qt.quarter(+) = q.qtrstr
GROUP BY qtr, q.qtrstr)
ORDER BY qtr;
Correct Output Generated:
QUARTER SUM_CONFIG
Q4-2006 160
Q1-2007 10
Q2-2007 10
Q3-2007 870
Q4-2007 50
Q1-2008 60
Q2-2008 60
Q3-2008 60
Q4-2008 60
====================================================================================================================================
New Requirement:Product column has been added.
SQL> select * from quarter_test3;
QUARTER CONFIG REP_DATE PRODUCT
Q1-2007 10 12-JAN-07 P1
Q2-2007 10 21-APR-07 P1
Q3-2007 870 14-AUG-07 P1
Q4-2007 50 15-NOV-07 P1
Q1-2008 60 02-JAN-09 P1
Q4-2006 160 02-DEC-06 P1
Q4-2006 997 02-DEC-06 P2
Q4-2007 60 14-NOV-07 P2
Q3-2007 970 14-NOV-07 P2
Q2-2007 20 21-APR-07 P2
Q1-2007 20 12-JAN-07 P2
QUARTER CONFIG REP_DATE PRODUCT
Q1-2008 70 12-JAN-08 P2
Expected Output:
Q4-2006 160 P1
Q1-2007 10 P1
Q2-2007 10 P1
Q3-2007 870 P1
Q4-2007 50 P1
Q1-2008 60 P1
Q2-2008 60 P1
Q3-2008 60 P1
Q4-2008 60 P1
Q4-2006 260 P2
Q1-2007 20 P2
Q2-2007 20 P2
Q3-2007 970 P2
Q4-2007 60 P2
Q1-2008 70 P2
Q2-2008 70 P2
Q3-2008 70 P2
Q4-2008 70 P2
My Query:
SELECT quarter,product,
CASE
WHEN qtr > TRUNC(SYSDATE, 'q')
THEN LAST_VALUE(sum_config IGNORE NULLS) OVER(ORDER BY qtr)
ELSE sum_config
END sum_config
FROM (SELECT qtr, q.qtrstr quarter,product, SUM(qt.config) sum_config
FROM (SELECT 'Q' || TO_CHAR(qtr, 'q-yyyy') qtrstr, qtr
FROM (SELECT ADD_MONTHS(ADD_MONTHS(TRUNC(SYSDATE, 'q'), -13), 3 *(LEVEL - 1)) qtr
FROM DUAL
CONNECT BY LEVEL <= 9)
ORDER BY qtr) q,
quarter_test3 qt
WHERE qt.quarter(+) = q.qtrstr
GROUP BY qtr,product, q.qtrstr)
ORDER BY substr(qtr,-4),substr(QTR,2,1)
Output:
QUARTER PRODUCT SUM_CONFIG
Q4-2006 P1 160
Q4-2006 P2 997
Q4-2007 P1 50
Q4-2007 P2 60
Q4-2008 70
Q2-2007 P1 10
Q2-2007 P2 20
Q2-2008 70
Q3-2007 P1 870
Q3-2007 P2 970
Q3-2008 70
QUARTER PRODUCT SUM_CONFIG
Q1-2007 P1 10
Q1-2007 P2 20
Q1-2008 P1 70
Q1-2008 P2 70
The query had not generated q2-2008,q3-2008,q4-2008 values [60]for P1...it had only generated q2-2008,q3-2008,q4-2008 values[70] for product P2.
Can you please advise me.You can make up the data using the model clause:
SQL> create table quarter_test3 (quarter, config, product)
2 as
3 select 'Q1-2007', 10, 'P1' from dual union all
4 select 'Q2-2007', 10, 'P1' from dual union all
5 select 'Q3-2007', 870, 'P1' from dual union all
6 select 'Q4-2007', 50, 'P1' from dual union all
7 select 'Q1-2008', 60, 'P1' from dual union all
8 select 'Q4-2006', 160, 'P1' from dual union all
9 select 'Q4-2006', 997, 'P2' from dual union all
10 select 'Q1-2007', 60, 'P2' from dual union all
11 select 'Q2-2007', 970, 'P2' from dual union all
12 select 'Q3-2007', 20, 'P2' from dual union all
13 select 'Q4-2007', 20, 'P2' from dual union all
14 select 'Q1-2008', 70, 'P2' from dual
15 /
Tabel is aangemaakt.
SQL> select 'Q' || to_char(mod(q,4) + 1) || '-' || to_char(trunc(q/4)) quarter
2 , config
3 , product
4 from quarter_test3
5 model
6 partition by (product)
7 dimension by (to_number(substr(quarter,4))*4 + to_number(substr(quarter,2,1)) - 1 q)
8 measures (config)
9 rules
10 ( config[for q from 2006*4 + 3 to 2008*4 + 3 increment 1]
11 = nvl(config[cv()],config[cv()-1])
12 )
13 order by product
14 , q
15 /
QUARTER CONFIG PR
Q4-2006 160 P1
Q1-2007 10 P1
Q2-2007 10 P1
Q3-2007 870 P1
Q4-2007 50 P1
Q1-2008 60 P1
Q2-2008 60 P1
Q3-2008 60 P1
Q4-2008 60 P1
Q4-2006 997 P2
Q1-2007 60 P2
Q2-2007 970 P2
Q3-2007 20 P2
Q4-2007 20 P2
Q1-2008 70 P2
Q2-2008 70 P2
Q3-2008 70 P2
Q4-2008 70 P2
18 rijen zijn geselecteerd.Regards,
Rob. -
Hi,
Currently we have a query (Created on Multicube - one is sales plan cube and another is Sales actuals).
When we run the query on a particular day (example: 7/10/2006), the report looks like as below:
Cal.Year/Month Sales plan Sales Actuals
Jan'06 310 305
Feb'06 280 277
Mar'06 310 309
Apr'06 300 300
MAy'06 310 305
June'06 300 305
July'06 310 90
The current report shows the whole month's Sales Plan (July'06 - 310) with Actual Sales for 9 days(for July'06 - 90). Whereas, We want to compare the sales Plan (first 9 days of the month) against the sales actuals for 9 days.
We do not have 0calday in both the cubes. Please help.
Thanks,David,
As rightly pointed out , you cannot get the plan value for 9 days if you do not have 0calday. However some things you can do...
1. Have a virtual KF which gets the number of days from the current calendar day ( system date ) to the first date of the month - this can be written with a simple exit since the first date is fixed.
2. calculate the plan value from that - pro rated plan value = plan value for month / number of days in month * number of days elapsed. If need be have the virtual KF return the ratio of number of days elapsed/number of days in the month
3. Now you can do the comparison assuming that the value of actuals will be till the current date and not beyond.
This is assuming that you can write a Virtual KF and the number of records is less enough to avoid any performance issues
Hope it helps..
Arun
Assign points if helpful
Message was edited by: Arun Varadarajan -
This is a weird one - like I said, camera roll is empty, but phone's memory is full. Under usage it shows that have 8.8 gb worth of photos (which is what it should be approximately). I cannot access the photos from computer as well - under import pictures it shows that the re are none available to be imported. The phones memory is full, i cannot get updates and etc, but CANNOT find the pictures.... please help!!!!
I found a fix guys, had the same thing... photos gone from camera role but still showed they are occupying the memory.
if you download iFunbox (www.i-funbox.com) you will be able to acccess you iphone, ipod, ipad system and can just copy to computer the jpg files from the RAW FILE SYSTEM or CAMERA tab by selecting all the photos. -
Approval process QUERY - Please help guys....
Hello Experts,
I have found some threads in this subject but non of them seem to work for me.
My need is :
when my employee tries to turn an order into an Invoice witch its card is set to groupname of 'over seas clients' the invoice will not be produced and the approval pop up will show.
this is what i tryed :
SELECT distinct 'true' FROM OINV T0 INNER JOIN OCRD T1 ON T0.CardCode = T1.CardCode INNER JOIN OCRG T2 ON T1.GroupCode = T2.GroupCode AND T2.GroupName 'Over seas clients' where T0.CardCode = $[$4.0.0]
nothing happens and the approval pop up never shows up.
Could someone Please help me with this query?
Thanks alot
D.medI thin approval process work like in this manner.
when you add any SO for particular condition matches then approval pop up will come, and then that SO gone to Approval. After approval user can able to make Invoice.
Hence i think in your case you need to made a query in SO that when the particular groupname is added then aproval should pop up.
Else you can kept the approval process in AR Invoice that if particular groupname is added then pop up.
For Approval process you need to select this query in Approval Template.
Maybe you are looking for
-
I have tried loading 3 different cds that I recently purchased into Itunes. I click the import cd button and Itunes goes through the motion of copying and importing the cds, but the songs are not in my music library. I have searched everywhere to f
-
Disable resend pop up message in firefox
It's extremely annoying to have to click on the pop up " RESEND or CANCEL " almost every time I click 'Back' on my firefox browser. I can't be bothered by having to do this extra step so often when it never happens in IE.
-
TS1347 sync contacts from google to ipad
how do I transfer my conatcts from google to my ipad mini? My calander was automatically transfered, but not my contacts. Thanks
-
SM:SERVICE CONTENT UPDATE failed
Hello SOLMAN Experts In our SOLMAN system 7.01 job SM:SERVICE CONTENT UPDATE is getting failed with below job log Job started Step 001 started (program RAGS_DSWP_SERV_CONTENT_UPDATE, variant , user ID ##### Problem occured when checking for new upda
-
I am amazed at the help I have gotten in the past so I have a new one. I have a list of email address (approx. 3000) and I need to remove everything up to and including the "@" symbol so that all I am left with if the mail domain. Obviously, the name