I used to do this bit of analysis in MS-SQL using the following bit of code
I've already changed the syntax to allow me to use it in Oracle, but the last section has now been running for about 20 hours! (Surely that can't be right..) It used to take about 3 minutes on a SQL box...
Any help from anyone would be really appreciated.
Oh, just to clarify, the bit I'm having trouble with is this bit:
Fi.
"The question should be, is it worth trying to do, not can it be done"
Code:
-- drop table if its there
begin
execute immediate 'drop table EfexorTrack';
exception
when others then
if sqlcode = -942 then
null; -- table does not exist
else
raise;
end if;
end;
-- Create a new table
Create Table EfexorTrack
(
RecID Number (10) not null,
CompID integer null,
PatientGid varchar(50) not null,
FirstDate date not null,
NextDate date null,
TreatmentDays integer null,
RxDays integer null,
Fullfil dec (9,2) null,
FRange char(1) null,
Quantity integer null,
Frequency integer null,
FirstMarket varchar(50) not null,
NextMarket varchar(50) null,
StatusIng char(1) null
);
-- create a trigger to mimic an identity column
ALTER TABLE EfexorTrack ADD (
CONSTRAINT dept_pk PRIMARY KEY (RecID));
CREATE SEQUENCE RecID_seq;
CREATE OR REPLACE TRIGGER Ident_bir
BEFORE INSERT ON EfexorTrack
FOR EACH ROW
WHEN (NEW.RecID IS NULL)
BEGIN
SELECT RecID_seq.NEXTVAL
INTO :NEW.RecID
FROM dual;
END;
/
-- Innsert some data
insert into EfexorTrack (PatientGid, FirstDate, Quantity, Frequency, FirstMarket)
select
Patient as PatientGid,
Rx_DATE as FirstDate,
DISPENSED_QTY as Quantity,
DOSAGE_FREQUENCY as Frequency,
Market as FirstMarket
from
Edinburgh
order by
PatientGid,
FirstDate;
-- now add the count by PatientGid so it increases by one
-- each time but starts counting again when it encounters
-- a new patient
Update EfexorTrack
Set CompID = RecID;
Update EfexorTrack
Set CompID =
(select count(*) from EfexorTrack Fee
where Fee.CompID <= EfexorTrack.CompID
and Fee.PatientGid = EfexorTrack.PatientGid);
I've already changed the syntax to allow me to use it in Oracle, but the last section has now been running for about 20 hours! (Surely that can't be right..) It used to take about 3 minutes on a SQL box...
Any help from anyone would be really appreciated.
Oh, just to clarify, the bit I'm having trouble with is this bit:
Code:
Update EfexorTrack
Set CompID =
(select count(*) from EfexorTrack Fee
where Fee.CompID <= EfexorTrack.CompID
and Fee.PatientGid = EfexorTrack.PatientGid);
Fi.
"The question should be, is it worth trying to do, not can it be done"