Query on for all and delete
Hi all,
I have developed a procedure. It is deleing records from a table.
Create or Replace PROCEDURE sidoc_delete(period date)
IS
/*CURSOR c5 IS
SELECT *
FROM ibsoifc.ibs_s_i_doc_receipt a
WHERE EXISTS (
SELECT 1
FROM ibsoifc.ibs_x_t_bill b
WHERE a.app_to_doc_no = b.doc_no
AND b.bill_month <= period
--AND b.bpref_no = :cons
AND b.balance_ser_amt = 0
AND b.balance_tax_amt = 0)
--AND a.bpref_no = :cons
AND a.app_to_doc_date <= period;*/
Cursor C5 is
SELECT a.rowid,a.*
FROM ibsoifc.ibs_s_i_doc_receipt a,
ibsoifc.ibs_x_t_bill b
WHERE a.app_to_doc_no = b.doc_no
AND b.bill_month <= period
AND b.balance_ser_amt = 0
AND b.balance_tax_amt = 0
AND a.app_to_doc_date <= period;
TYPE tsch IS TABLE OF c5%ROWTYPE;
vtsch tsch;
cnt NUMBER := 0;
stime NUMBER;
etime NUMBER;
DURATION NUMBER;
rcount NUMBER;
errorsd PLS_INTEGER;
ecode NUMBER;
val1 VARCHAR2 (100);
val2 VARCHAR2 (100);
val3 VARCHAR2 (100);
val4 VARCHAR2 (100);
BEGIN
BEGIN
stime := DBMS_UTILITY.get_time ();
OPEN c5;
LOOP
FETCH c5
BULK COLLECT INTO vtsch LIMIT 1000;
IF vtsch.COUNT = 1000
THEN
cnt := cnt + 1;
END IF;
FORALL i IN vtsch.first .. vtsch.last SAVE EXCEPTIONS
Delete from ibsoifc.ibs_s_i_doc_receipt where app_to_doc_date <= Period;
commit;
EXIT WHEN c5%NOTFOUND;
END LOOP;
etime := DBMS_UTILITY.get_time ();
DURATION := ((etime - stime) / 100) / 60;
rcount :=
(cnt * 1000) + vtsch.COUNT - NVL (SQL%BULK_EXCEPTIONS.COUNT, 0);
INSERT INTO process_stage_log
VALUES (SYSDATE, 'IBS_S_I_DOC_RECEIPTS-D', DURATION, rcount);
CLOSE c5;
COMMIT;
EXCEPTION
WHEN OTHERS
THEN
Begin
errorsd := SQL%BULK_EXCEPTIONS.COUNT;
IF errorsd > 0
THEN
FOR j IN 1 .. errorsd
LOOP
ecode := SQL%BULK_EXCEPTIONS (j).ERROR_CODE;
val1 :=
vtsch (SQL%BULK_EXCEPTIONS (j).ERROR_INDEX).biz_part_code;
val2 :=
vtsch (SQL%BULK_EXCEPTIONS (j).ERROR_INDEX).bpref_no;
val3 :=
vtsch (SQL%BULK_EXCEPTIONS (j).ERROR_INDEX).apply_date;
val4 :=
vtsch (SQL%BULK_EXCEPTIONS (j).ERROR_INDEX).service_code;
INSERT INTO process_error_log
VALUES (SYSDATE, ecode, 'IBS_S_I_DOC_RECEIPTS', 'biz_part_code',
val1, 'bpref_no', val2, 'apply_date', val3, 'service_code', val4,'DELETE');
etime := DBMS_UTILITY.get_time ();
DURATION := ((etime - stime) / 100) / 60;
rcount := (cnt * 1000) + vtsch.COUNT - NVL (SQL%BULK_EXCEPTIONS.COUNT, 0);
INSERT INTO process_stage_log VALUES (SYSDATE, 'IBS_S_I_DOC_RECEIPTS-D', DURATION, rcount);
END LOOP;
END IF;
Exception
When others then
etime := DBMS_UTILITY.get_time ();
DURATION := ((etime - stime) / 100) / 60;
INSERT INTO process_stage_log
VALUES (SYSDATE, 'IBS_S_I_DOC_RECEIPTS-D', DURATION, 0);
End;
END;
END sidoc_delete;The table IBS_S_I_DOC_RECEIPTS is having 50 million records.
The table IBS_X_T_BILL is having is having 39 million records.
The procedure is open a cursor
Cursor C5 is
SELECT a.rowid,a.*
FROM ibsoifc.ibs_s_i_doc_receipt a,
ibsoifc.ibs_x_t_bill b
WHERE a.app_to_doc_no = b.doc_no
AND b.bill_month <= period
AND b.balance_ser_amt = 0
AND b.balance_tax_amt = 0
AND a.app_to_doc_date <= period;and deleting by the following command
FORALL i IN vtsch.first .. vtsch.last SAVE EXCEPTIONS
Delete from ibsoifc.ibs_s_i_doc_receipt where app_to_doc_date <= Period;question
1.The above delete, will delete all the record which below to date or from cursor active set record which below to the date?.
I run the above procedure for 5 years
and my procedure is running sill now and it is started wednesday morning. so for just 15 laks only deleted.
How to improve the procedure performance.
please guide me
kanish
This is my actual coding which running now
Create or Replace PROCEDURE sidoc_delete(period date)
IS
/*CURSOR c5 IS
SELECT *
FROM ibsoifc.ibs_s_i_doc_receipt a
WHERE EXISTS (
SELECT 1
FROM ibsoifc.ibs_x_t_bill b
WHERE a.app_to_doc_no = b.doc_no
AND b.bill_month <= period
--AND b.bpref_no = :cons
AND b.balance_ser_amt = 0
AND b.balance_tax_amt = 0)
--AND a.bpref_no = :cons
AND a.app_to_doc_date <= period;*/
Cursor C5 is
SELECT a.rowid,a.*
FROM ibsoifc.ibs_s_i_doc_receipt a,
ibsoifc.ibs_x_t_bill b
WHERE a.app_to_doc_no = b.doc_no
AND b.bill_month <= period
AND b.balance_ser_amt = 0
AND b.balance_tax_amt = 0
AND a.app_to_doc_date <= period;
TYPE tsch IS TABLE OF c5%ROWTYPE;
vtsch tsch;
cnt NUMBER := 0;
stime NUMBER;
etime NUMBER;
DURATION NUMBER;
rcount NUMBER;
errorsd PLS_INTEGER;
ecode NUMBER;
val1 VARCHAR2 (100);
val2 VARCHAR2 (100);
val3 VARCHAR2 (100);
val4 VARCHAR2 (100);
BEGIN
BEGIN
stime := DBMS_UTILITY.get_time ();
OPEN c5;
LOOP
FETCH c5
BULK COLLECT INTO vtsch LIMIT 1000;
IF vtsch.COUNT = 1000
THEN
cnt := cnt + 1;
END IF;
FORALL i IN vtsch.first .. vtsch.last SAVE EXCEPTIONS
Delete from ibsoifc.ibs_s_i_doc_receipt where rowid= vtsch(i).rowid;
--app_to_doc_no = vtsch(i).app_to_doc_no;
commit;
EXIT WHEN c5%NOTFOUND;
END LOOP;
etime := DBMS_UTILITY.get_time ();
DURATION := ((etime - stime) / 100) / 60;
rcount :=
(cnt * 1000) + vtsch.COUNT - NVL (SQL%BULK_EXCEPTIONS.COUNT, 0);
INSERT INTO process_stage_log
VALUES (SYSDATE, 'IBS_S_I_DOC_RECEIPTS-D', DURATION, rcount);
CLOSE c5;
COMMIT;
EXCEPTION
WHEN OTHERS
THEN
Begin
errorsd := SQL%BULK_EXCEPTIONS.COUNT;
IF errorsd > 0
THEN
FOR j IN 1 .. errorsd
LOOP
ecode := SQL%BULK_EXCEPTIONS (j).ERROR_CODE;
val1 :=
vtsch (SQL%BULK_EXCEPTIONS (j).ERROR_INDEX).biz_part_code;
val2 :=
vtsch (SQL%BULK_EXCEPTIONS (j).ERROR_INDEX).bpref_no;
val3 :=
vtsch (SQL%BULK_EXCEPTIONS (j).ERROR_INDEX).apply_date;
val4 :=
vtsch (SQL%BULK_EXCEPTIONS (j).ERROR_INDEX).service_code;
INSERT INTO process_error_log
VALUES (SYSDATE, ecode, 'IBS_S_I_DOC_RECEIPTS', 'biz_part_code',
val1, 'bpref_no', val2, 'apply_date', val3, 'service_code', val4,'DELETE');
etime := DBMS_UTILITY.get_time ();
DURATION := ((etime - stime) / 100) / 60;
rcount := (cnt * 1000) + vtsch.COUNT - NVL (SQL%BULK_EXCEPTIONS.COUNT, 0);
INSERT INTO process_stage_log VALUES (SYSDATE, 'IBS_S_I_DOC_RECEIPTS-D', DURATION, rcount);
END LOOP;
END IF;
Exception
When others then
etime := DBMS_UTILITY.get_time ();
DURATION := ((etime - stime) / 100) / 60;
INSERT INTO process_stage_log
VALUES (SYSDATE, 'IBS_S_I_DOC_RECEIPTS-D', DURATION, 0);
End;
END;
END sidoc_delete;kanish
Similar Messages
-
Editing the Query name for all reports in PRD.
Dear All,
I have created 25 reports using Query Designer.We have moved all the reports to BI Production. And Clients are using these reports using the Tool Bex Analyser.
Every time they are navigating through open Query -> Info Areas -> Data targets and Query.
Instead of going this way, is there any other way to Open a query easily.
And they wants to modify the Report name and the Technical name for all the reports. Can we able to edit the Query name for all reports, or do i need to go for SAVE AS for all querys.
Pls Suggest.
Thanks,
RamHi Ram,
1. For the first question; if it user specific query then ask the users to save them at the FAVORITES so that there is no need to go to the dataprovider specific.
Or they can create the reports as favorites user menu screen of that particular user.
2. In order to change the technical name and description of the queries goto RSZC t-code> give the source and target infoprovider as same> select queries>click on the reports>click on transfer selections-->
Then you get a screen to change the description and technical name.
But this is pertained to Infoprovider level.
You can see all the reports on the infoprovider (cube/ods).
Hope you understood.
Regards,
Ravi Kanth -
Make this query into for all entries
Hello Experts,
please change this query into for all entries to increase performance
loop at itab1.
SELECT single b~vtext INTO itab2
FROM vbkd AS a
INNER JOIN tvkggt AS b
ON akdkg1 = bkdkgr
WHERE a~vbeln EQ itab1-vbeln_vauf
AND a~posnr EQ itab1-posnr_vauf.
endloop.
Thank you so much for all the replies.as I write again and again, then performance is mainly increased but correct index usage
SELECT single b~vtext
INTO itab2
FROM vbkd AS a
INNER JOIN tvkggt AS b
ON ..... spras ???
bkdkgr = akdkg1
WHERE a~vbeln EQ itab1-vbeln_vauf
AND a~posnr EQ itab1-posnr_vauf.
You access vbkd with the primary key vbeln and posnr
and then you switch to tvkggt where you need spras and kdgr for the primary key
With spras you statement is incorrect you get one text it is unclear in which language,
it might be that there is onyl one, but still you *** it to the statement to use the index.
spras = sy-langu might be o.k.
I.e.
IF NOT ( itab1 is initial ).
SELECT single b~vtext
INTO itab2
FROM vbkd AS a
INNER JOIN tvkggt AS b
ON b~spras = sy_langu
b~kdkgr = a~kdkg1
FOR ALL ENTRIES in itab1
WHERE a~vbeln EQ itab1-vbeln_vauf
AND a~posnr EQ itab1-posnr_vauf.
ENDIF.
Siegfried -
I'm having trouble deleting mail. When I select all and delete it doen't always work. Is there a glitch inthis app?
Have you reset the iPad by holding down on the sleep and home buttons at the same time for about 10 seconds until the Apple logo appears on the screen? If that doesn't resolve this, you can try resetting all settings. Settings>General>Reset>Reset All Settings. You will not lose any data, but all device settings will have to be entered again.
If that doesn't fix it, your next step might be to backup then erase all content and settings or restore the iPad to factory settings. See how if goes if you reset all settings first. -
Search file for text and delete the found text. How?
I need to know how to search a file for text and delete the found text. I think grep will let you do this but not sure of the syntax.
Hi Dmcrory,
In addition to what Camelot and nobody loopback point out, one must also consider the fact that UNIX text tools are largely line based. You also fail to tell us for what kind of text you are searching. If you are looking for multiple words, there's a very good chance of finding the expression wrapped onto different lines. With hyphenation, even single words can wrap to multiple lines. Tools that search line-by-line will miss these unless you use multiline techniques.
Multiline substitutions require that you write "read-ahead" code for the command line tool that you're using and that you take that into account in the substitution. Given how you want the results to be printed out, you may also want to preserve any newlines found in the match, which is even more difficult. That could bring up the subject of line endings but that's a completely different topic.
I apologize if this sounds discouraging. Multiline searches aren't needed that often and in most of those cases, exceptions can be dealt with by hand. I just didn't want you to get surprised by it. To give you an idea of how easy basic substitution is, have a look at Tom Christiansen's Cultured Perl: One-liners 102 and One-liners 101. Both have some "in-place" substitution examples.
Gary
~~~~
MIT:
The Georgia Tech of the North -
How can I transfer all my photos on iPhone to iCloud for archive and delete them off my phone?
I do not want to simply backup my phone with iCloud. My iPhone's memory is full and I would like to transfer all my 10,000+ photos to iCloud for safe keeping, and delete them off my phone. Could I do that? I know that iCloud is typically used for backing up the phone and works like a 'mirror' to the phone, but I want to use it more as an archive drive. Please advise!
The only iCloud feature that meets this requirement is the iCloud Photo Library (Beta). I don't think that I would trust all my photos to a Beta-level product.
You could create a Dropbox Account and move the photos to it or move the photos to your computer. -
When using the webmail application for earthlink email, the "check all" option to select an entire page of messages at once no longer functions. Same problem with the "delete" buttons that are located at the top and bottom of the page with multiple messages. Consequently, the only way to delete a message is to open the message and delete it in that view -- extremely tedious if there are a lot of messages.
This is a recent change, in the last few days. Everything works fine in I explorer. Earthlink support suggested I start Firefox in safe mode and restore firefox default settings. I went through the process on the help page. It didn't help.
I'll provide the earthlink link, but it is my email page that is the problem.Same here.
- select multiple mails with the SEARCH option (manually selecting seems to work fine)
- click the move button
- list of folders appears (witn account & cancel options that both still work)
- click on a folder
- mail flies to this folder (animated)
- list of folders remains visible
- the cancel button does NOT work
- the accounts button takes you back to the root "directory" of your accounts
- in my case "live" and "exchange"
- this screen is a dead end. Clicking on both the account names and the cancel button do not work
A complete restart fixes the problem -
Need different processes for Update and Delete buttons
I'm using a customized version of the Issue Tracker sample application. I've added a table called project_person(project_id,person_id) so that a project can have multiple people assigned to it and so that one person can have multiple projects. I have a form report that lists all of the projects with an edit link which opens one project. On the individual project page, there are page items for each of the columns in the project table and a item for the person assigned to the project--this item is pulled from the separate project_person table. I have two buttons--Delete and Apply Changes. If you click on Apply Changes, the project table should be updated and then the project_person table if the assignment was changed. If you click on Delete, it should delete the project_person record first and then delete the project record. I created a new conditional pl/sql process that updated two tables if 'Apply Changes' button is cliicked. I then created a separate conditional process when the Delete button is clicked. This conditional process checks to see if a record in the project_person table exists, and if so, delete the record. Then delete the project record.
The update process works fine. The delete process reloads the list of projects with a success message at the top without actually doing a delete and I have no idea why. Does anyone have any suggestions?
I am not using the automatic row processing, but should I? Or is it ok to have the two separate conditions for the two different buttons?Hello again Miah,
Check the "Sequence Number" for your processes. Typically, APEX will increment by 10, each time you create a Page Process as I recall. You can set this to be any number you want; even if you duplicate the sequence number (ie: you can have multiple Sequence 10 processes).
Make sure that your Delete process is firing properly and walk through the logic in the source code to be sure that any "IF" or "WHERE" logic is satisfied. For example:
Begin
delete from emp_table
where 1=2;
End;If this was your page process code - you would receive a SUCCESS message because the PL/SQL code executed successfully, even though nothing will be deleted since 1 will NEVER equal 2.
So, check Delete Source carefully.
{size:14}{color:green}Can you post the code from your delete page process here?{color}{size}
Good luck,
Don.
REWARDS: Please remember to mark helpful or correct posts on the forum, not just for my answers but for everyone! :)
Edited by: dfcii© on Oct 27, 2009 10:55 AM -
FBE2: BAPI or FM for Changing and Deleting Payment Advice
Hi,
I am looking for BAPI or FM for changing & deleting payment advice as we can accomplish from FBE2.
This is EC 6.0 upgrade issue for not be able to post using CALL TRANSACTION in background mode.
I tried the below FM's in the Function group FARMATCH, but all have them have the follwing code to select payment advice Header Table [AVIK].
SELECT * FROM AVIK INTO TABLE LT_AVIK WHERE (LT_WHERE) AND
AVSID LIKE '09%'. "This is not the case for my requirement
FARMATCH_CHANGE_PAYMENT_ADVICE
FARMATCH_DELETE_PAYMENT_ADVICE
I found another set of FM's REMADV_CHANGE & REMADV_DELETE but I am not sure if i can
achieve the same functionality of change and delete that we can do using FBE2.
If anyone had similar scenario, Appreicate your feedback.Below is a sample code.
I am able to delete the details....
Take a look...:)...imp to add wait for few seconds
REPORT z.
PARAMETER: vbeln TYPE vbak-vbeln.
PARAMETERS: fplnr TYPE fplnr.
DATA: t_zfpla TYPE STANDARD TABLE OF fplavb WITH HEADER LINE.
DATA: t_zfplt TYPE STANDARD TABLE OF fpltvb WITH HEADER LINE.
DATA: t_fpla_new TYPE STANDARD TABLE OF fplavb WITH HEADER LINE.
DATA: t_fpla_old TYPE STANDARD TABLE OF fplavb WITH HEADER LINE.
DATA: t_fplt_new TYPE STANDARD TABLE OF fpltvb WITH HEADER LINE.
DATA: t_fplt_old TYPE STANDARD TABLE OF fpltvb WITH HEADER LINE.
*DATA fplnr TYPE fplnr.
IF NOT vbeln IS INITIAL.
SELECT SINGLE rplnr INTO fplnr FROM vbak WHERE vbeln = vbeln.
ENDIF.
CALL FUNCTION 'BILLING_SCHEDULE_READ'
EXPORTING
fplnr = fplnr
TABLES
zfpla = t_zfpla
zfplt = t_zfplt.
LOOP AT t_zfpla.
MOVE-CORRESPONDING t_zfpla TO t_fpla_old.
t_fpla_old-updkz = 'D'.
APPEND t_fpla_old.
ENDLOOP.
LOOP AT t_zfplt.
MOVE-CORRESPONDING t_zfplt TO t_fplt_old.
t_fplt_old-updkz = 'D'.
APPEND t_fplt_old.
ENDLOOP.
BREAK-POINT.
*CALL FUNCTION 'BILLING_SCHEDULE_SAVE'
TABLES
fpla_new = t_fpla_new
fpla_old = t_fpla_old
fplt_new = t_fplt_new
fplt_old = t_fplt_old.
DATA fpltr TYPE fpltr.
CALL FUNCTION 'BILLING_SCHEDULE_MAINTAIN'
EXPORTING
I_FPLA =
I_FPLT =
i_upd_fpla = 'X'
i_upd_fplt = 'X'
i_fplnr = fplnr
IMPORTING
E_DATALOSS =
E_UPD_FPLA =
E_UPD_FPLT =
e_fplnr = fplnr
e_fpltr = fpltr
TABLES
fpla_new = t_fpla_new
fpla_old = t_fpla_old
fplt_new = t_fplt_new
fplt_old = t_fplt_old.
WAIT UP TO 2 SECONDS. -
Can validations be done inside FOR ALL and can we use conventional insert
Hi All,
I have to move millions of data from one 'table1' to ' table 2'. Table 2 is equal Table 1 columns+ an extra column . data for the extra column is retrieved from table 3 using foreign keys of table 3 and table 1.how shud i do it using bulk collect and for all insert... I have given the sample code for my problem..
TABLES:
table 1 columns: emp_name, emp_id , emp_add, emp_txt
table 2 columns: emp_name, emp_id, emp_add,emp_txt,emp_ref
table 3 column: emp_txt,emp_ref,emp_size
CODE:
create or replace
procedure bulk_proc IS
v_emp_ref varchar2(20);
cursor cur_t1 is
select * from table 1;
TYPE bulk_t1 is table of cur_t1%rowtype;
v_bulk_t1 bulk_t1;
cursor cur_t3 is
select a.emp_txt,b.emp_ref from table 1 a, table 3 b where a.emp_txt = b.emp_txt;
TYPE bulk_t3 is table of cur_t3%rowtype;
v_bulk_t3 bulk_t3;
begin
open cur_t1;
open cur_t3;
loop
fetch cur_t1 bulk collect into v_bulk_t1 ;
exit when v_bulk_t1.count=0;
fetch cur_t3 bulk collect into v_bulk_t3 ;
exit when v_bulk_t3.count=0;
for i in v_bulk_t1.first..v_bulk_t1.last loop
for j in v_bulk_t3.first..v_bulk_t3.last loop
if (v_bulk_t1(i).emp_txt = v_bulk_t3(j).emp_txt) then
v_emp_ref := v_bulk_t1(i).emp_txt ;
else
v_emp_ref := null;
end if;
for all m in 1..v_bulk_t1.count
insert into t2(emp_name, emp_id, emp_add,emp_txt,emp_ref) values
(v_bulk_t1(m).emp_name,
v_bulk_t1(m).emp_id,
v_bulk_t1(m).emp_add,
v_bulk_t1(m).emp_txt,
v_emp_ref);
end loop;
end loop;
end loop;
close cur_t3;
close cur_t1;
end bulk_proc;
can we do validations inside FOR ALL command..i am getting error.is it possible to use conventional insert inside 'for all command' or do we have to use only 'insert ti values v_bulk_t1(i)' like that....Do i have to use only conventional cursor for this problem?...please help me..1.I want to push 18 million records from one table to another table with validations....Can i use ur code for it? You can always test how the example Tubby provided works in your environment.
Usually a single SQL statement is the right way to go.
http://asktom.oracle.com/pls/apex/f?p=100:11:0::::P11_QUESTION_ID:760210800346068768
(memorize the mantra)
Another option you have is to use CTAS (Create Table ... As Select ...) or use the APPEND hint while inserting.
Make sure first that you understand how it works:
You can find many examples including clear explanations by doing a search on http://asktom.oracle.com
2.Can we do normal insert and validations inside FOR ALL insert loop... Afaik, you cannot. ( But it wouldn't surprise me if Michael comes up with an example using dynamic SQL ;) )
http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14261/forall_statement.htm#LNPLS01321
Alternatively you should investigate if it's possible to adjust your query/queries in such a way so that only records that you want to insert are selected.
In other words: use the WHERE-clause from your query to validate rightaway instead of selecting records thatyou don't want/need at all.
3.How variables are stored in BULK COLLECT ..Is it storing pattern differs from cursor.......Sorry, I don't understand what you mean here.
4.In which scenarios we should not use COLLECTIONS ...Please help me...That's totally dependent of the scenario/requirement.
Example:
http://asktom.oracle.com/pls/apex/f?p=100:11:0::::P11_QUESTION_ID:1058232381458 -
Query using Union All and CTEs is slow
TypePatient
[ednum] int NOT NULL, PK
[BackgroundID] int NOT NULL, FK
[Patient_No] varchar(50) NULL, FK
[Last_Name] varchar(30) NULL,
[First_Name] varchar(30) NULL,
[ADateTime] datetime NULL,
Treat
[ID] int NOT NULL, PK
[Ednum] numeric(10, 0) NOT NULL, FK
[Doctor] char(50) NULL,
[Dr_ID] numeric(10, 0) NULL,
background
[ID] int NOT NULL, PK
[Patient_No] varchar(50) NULL, FK
[Last_Name] char(30) NULL,
[First_Name] char(30) NULL,
[DateofBirth] datetime NULL,
pdiagnose
[ID] int NOT NULL, PK
[Ednum] int NOT NULL, FK
[DSMNo] char(10) NULL,
[DSMNoIndex] char(5) NULL,
substance
[ID] int NOT NULL, PK
[Ednum] int NOT NULL, FK
[Substance] varchar(120) NULL,
DXCAT
[id] int NULL, PK
[dx_description] char(100) NULL,
[dx_code] char(10) NULL,
[dx_category_description] char(100) NULL,
[diagnosis_category_code] char(10) NULL)
Substance
ID
Ednum
Substance
1
100
Alcohol Dependence
4
200
Caffeine Dependence
5
210
Cigarettes
dxcat
id
dx_description
dx_code
dx_category_description
diagnosis_category_code
10
Tipsy
zzz
Alcohol
SA
20
Mellow
ppp
Mary Jane
SA
30
Spacey
fff
LSD
SA
50
Smoker
ggg
Nicotine
SA
pdiagnose
ID
Ednum
DSMNo
Diagnosis
1
100
zzz
Alcohol
2
100
ddd
Caffeine
3
210
ggg
Smoker
4
130
ppp
Mary Jane
TypePatient
ednum
Patient_No
Last_Name
First_Name
ADateTime
100
sssstttt
Wolly
Polly
12/4/2013
130
rrrrqqqq
Jolly
Molly
12/8/2013
200
bbbbcccc
Wop
Doo
12/12/2013
210
vvvvwww
Jazz
Razz
12/14/2013
Treat
ID
Ednum
Doctor
Dr_ID
2500
100
Welby, Marcus
1000
2550
200
Welby, Marcus
1000
3000
210
Welby, Marcus
1000
3050
130
Welby, Marcus
1000
background
ID
Patient_No
Last_Name
First_Name
DateofBirth
2
sssstttt
Wolly
Polly
8/6/1974
3
rrrrqqqq
Jolly
Molly
3/10/1987
5
bbbbcccc
Wop
Doo
8/12/1957
6
vvvvwww
Jazz
Razz
7/16/1995
Desired output:
Staff ID
Doctor
Patient_No
Client Name
Date of Service
Ednum
DX Code
DX Cat
DX Desc
Substance
1000
Welby, Marcus
bbbcccc
Wop, Doo
12/12/2013
200
Caffeine Dependence
1000
Welby, Marcus
rrrqqq
Jolly, Molly
12/8/2013
130
ppp
SA
Mary Jane
1000
Welby, Marcus
sssttt
Wolly, Polly
12/4/2013
100
zzz
SA
Alcohol
1000
Welby, Marcus
sssttt
Wolly, Polly
12/4/2013
100
ddd
SA
LSD
1000
Welby, Marcus
sssttt
Wolly, Polly
12/4/2013
100
Alcohol Dependence
1000
Welby, Marcus
vvvvwww
Jazz, Razz
12/14/2013
210
ggg
SA
Smoker
1000
Welby, Marcus
vvvvwww
Jazz, Razz
12/14/2013
210
Cigarettes
A patient is assigned an ednum. There are two different menus for staff to enter
diagnoses. Each menu stores the entries in a different table. The two tables are substance and pdiagnose. A patient’s diagnosis for a substance abuse can be entered in one table and not the other.
The number of entries for different substances for each patient can vary between the two tables. John Doe might be entered for alcohol and caffeine abuse in the pdiagnosis table and entered only for caffeine abuse in the substance table. They are only
linked by the ednum which has nothing to do with the diagnosis/substance. The substance entered in one table is not linked to the substance entered in the other. A query will not put an entry for alcohol from the pdiagnosis table on the same row as an alcohol
entry from the substance table except by chance. That is the reason for the way the query is written.
The query accepts parameters for a Dr ID and a start and end date. It takes about 7 to 15 seconds to run. Hard coding the dates cuts it down to about a second.
I might be able to select directly from the union all query instead of having it separate. But then I’m not sure about the order by clauses using aliases.
Is there a way to rewrite the query to speed it up?
I did not design the tables or come up with the process of entering diagnoses. It can’t be changed at this time.
Please let me know if you notice any inconsistencies between the DDLs, data, and output. I did a lot of editing.
Thanks for any suggestions.
with cte_dxcat (Dr_ID, Doctor, Patient_No,Last_Name,
First_Name, Adatetime,Ednum,
dx_code,diagnosis_category_code,dx_description,substance,
DateofBirth) as
(Select distinct t.Dr_ID, t.Doctor, TP.Patient_No,TP.Last_Name,
TP.First_Name, TP.Adatetime as 'Date of Service',TP.Ednum,
DXCAT.dx_code,DXCAT.diagnosis_category_code,DXCAT.dx_description,
null as 'substance',BG.DateofBirth
From TypePatient TP
inner join treat t on TP.ednum = t.Ednum
inner join background BG on BG.Patient_No = TP.Patient_No
inner join pdiagnose PD on TP.Ednum = PD.Ednum
inner join Live_Knowledge.dbo.VA_DX_CAT_MAPPING DXCAT on DXCAT.dx_code = PD.DSMNo
Where (TP.Adatetime >= convert(varchar(10), :ST, 121)+ ' 00:00:00.000'
and TP.Adatetime <= convert(varchar(10), :SP, 121)+ ' 23:59:59.000')
and DXCAT.diagnosis_category_code = 'SA'
and t.Dr_ID =:DBLookupComboBox2
cte_substance (Dr_ID, Doctor, Patient_No,Last_Name,
First_Name,Adatetime, Ednum,
dx_code,diagnosis_category_code,dx_description,Substance,DateofBirth) as
(Select distinct t.Dr_ID, t.Doctor, TP.Patient_No,TP.Last_Name,
TP.First_Name, TP.Adatetime as 'Date of Service', TP.Ednum,
null as 'dx_code',null as 'diagnosis_category_code',null as 'dx_description',s.Substance, BG.DateofBirth
From TypePatient TP
inner join treat t on TP.ednum = t.Ednum
inner join background BG on BG.Patient_No = TP.Patient_No
inner join pdiagnose PD on TP.Ednum = PD.Ednum
inner join substance s on TP.Ednum = s.Ednum
Where (TP.Adatetime >= convert(varchar(10), '12/1/2013', 121)+ ' 00:00:00.000'
and TP.Adatetime <= convert(varchar(10), '12/31/2013', 121)+ ' 23:59:59.000')
and t.Dr_ID =:DBLookupComboBox2
cte_all (Dr_ID, Doctor, Patient_No,Last_Name,
First_Name,Adatetime, Ednum,
dx_code,diagnosis_category_code,dx_description,Substance,DateofBirth) as
(select cte_dxcat.Dr_ID as 'Staff ID', cte_dxcat.Doctor as 'Doctor',
cte_dxcat.Patient_No as 'Patient_No',
cte_dxcat.Last_Name as 'Last',cte_dxcat.First_Name as 'First',
cte_dxcat.Adatetime as 'Date of Service',cte_dxcat.Ednum as 'Ednum',
cte_dxcat.dx_code as 'DX Code',cte_dxcat.diagnosis_category_code as 'DX Category Code',
cte_dxcat.dx_description as 'DX Description',
cte_dxcat.substance as 'Substance',cte_dxcat.DateofBirth as 'DOB'
from cte_dxcat
union all
select cte_substance.Dr_ID as 'Staff ID', cte_substance.Doctor as 'Doctor',
cte_substance.Patient_No as 'Patient_No',
cte_substance.Last_Name as 'Last',cte_substance.First_Name as 'First',
cte_substance.Adatetime as 'Date of Service',cte_substance.Ednum as 'Ednum',
cte_substance.dx_code as 'DX Code',cte_substance.diagnosis_category_code as 'DX Category Code',
cte_substance.dx_description as 'DX Description',
cte_substance.substance as 'Substance',cte_substance.DateofBirth as 'DOB'
from cte_substance)
select cte_all.Dr_ID as 'Staff ID', cte_all.Doctor as 'Doctor',
cte_all.Patient_No as 'Patient_No',
(cte_all.Last_Name + ', '+ cte_all.First_Name) as 'Client Name',
cte_all.Adatetime as 'Date of Service',cte_all.Ednum as 'Ednum',
cte_all.dx_code as 'DX Code',cte_all.diagnosis_category_code as 'DX Category Code',
cte_all.dx_description as 'DX Description',
cte_all.substance as 'Substance',
CONVERT(char(10), cte_all.DateofBirth,101) as 'DOB'
from cte_all
order by cte_all.Patient_No,cte_all.AdatetimePlease post real DDL instead of your invented non-language, so that people do not have to guess what the keys, constraints, Declarative Referential Integrity, data types, etc. in your schema are. Learn how to follow ISO-11179 data element naming conventions
and formatting rules. Your rude, non-SQL narrative is so far away from standards I cannot even use you as a bad example in book.
Temporal data should use ISO-8601 formats (we have to re-type the dialect you used!). Code should be in Standard SQL as much as possible and not local dialecT.
This is minimal polite behavior on SQL forums. You posted a total mess! Do you really have patients without names?? You really use a zero to fifty characters for a patient_nbr??? Give me an example. That is insane!
Your disaster has more NULLs than entire major corporate systems. Since you cannot change it, can you quit? I am serious. I have been employed in IT since 1965, and can see a meltdown.
I looked at this and I am not even going to try to help you; it is not worth it. I am sorry for you; you are in an environment where you cannot learn to do any right.
But you are still responsible for the rudeness of not posting DDL.
--CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
in Sets / Trees and Hierarchies in SQL -
Select query like For all Entries
Hi,
I have a requirement like:
I need to extract data (BKTXT) from table BKPF based on some criteria, into one internal table and I need to query on REGUP table for the above data, the selection criteria on REGUP as follows:
BKTXT(Document Header Text with 25 Char) is a combination of DATE and character string.
Ex: bkpf-bktxt = 20060710-PL02 (YYYYMMDD)
it is like LAUFD + LAUFI (of table REGUP)
i.e: LAUFD (REGUP) = 07/10/2006 (MM/DD/YYYY) and LAUFI(REGUP) = PL02
here I am thinking to use a select query on REGUP using FOR ALL ENTRIES of table i_bkpf..
How can I change the date format YYYYMMDD to MM/DD/YYYY for my requirement?
(( Run-on Date (REGUP-LAUFD) = the first 8 characters in the Document Header Text (BKPF- BKTXT) in MM/DD/YYYY date format (e.g. 07/10/2006)
Run ID (REGUP-LAUFI) = the 10th character through the 15th character in the Document Header Text (BKPF- BKTXT)It is not possible to do in the way you are thinking of doing. "For all entries" requires you to have the itab table field and the database table field to have the same type and length. So something like below <u>will not work</u>.
TABLES: regup.
DATA: BEGIN OF itab OCCURS 0,
text LIKE bkpf-bktxt.
DATA: END OF itab.
DATA: BEGIN OF itab_regup OCCURS 0.
INCLUDE STRUCTURE regup.
DATA: END OF itab_regup.
SELECT * INTO TABLE itab_regup
FROM regup FOR ALL ENTRIES IN itab
WHERE laufd = itab-text+0(8).
If you run this code, you will get an error as follows:
<i>"When using the addition "FOR ALL ENTRIES IN itab", the fields "LAUFD" and "ITAB-TEXT+0(8)" must have the same type and length."</i> -
Adhoc Query iview for IT0006 and IT0021
Hi All
SAP has given page in MSS for IT0006 and IT0021 - 'Generic iview Test Page'. This page has 3 iViews : one for employee search , second for IT0006 and third for IT0021. This page is working ok and retrieving data from back end.
But If I replace IT0006 or IT00021 query with my own query then the error on Page is 'System cannot retrieve data'
SAP standard query given in iview property is MSS_IT0006, If I replace this query with my query ZMSS_IT0006 then I get above error.
I have created query ZMSS_IT0006 in work area:- global , usergroup:- /SAPQUERY/MS
Is there any aditional config need if we replace standard SAP query by our own query?
Amit.in the adhoc query we can select the periods based on the frequency but the dates will not get default
As in the Pay roll driver the dates get defaulted based on the settings made in Control Record Status
so i dont think this is possible thru Standrad
let wait for expert views -
Urgent!! Default query template for all users.
Hi Guys,
How do I set the default template for queries for all users.
I saved the default template and did the setting settings>query on embed>use the default template. So the template eorked for me.
But when a different usre tried, the template did not load for him.
So is there a specific setting that can be done so that it apllies for all users.
Thanks
simmiHi Simmi,
There is a way that you can do this. Check this post for details as provided by Prakash:
Re: Permanent BW Excel Template
Hope this helps... -
Feature Request: Functions for Renaming and Deleting LrDevelopPresets
As it stands, there is no way to delete an LrDevelopPreset programmatically - short of deleting the develop preset lrtemplate file, but even then the effect doesn't take place until after restarting Lightroom.
Likewise, there is no good way to rename an LrDevelopPreset.
Rename and delete functions would be very helpful to plugins that work with lrdevelopresets.
Thanks,
RobHi
Can you please post the archived project so that I can test in the latest internal builds and take the necessary actions?
Maybe you are looking for
-
I've spent 1/2 the day trying to troubleshoot this problem and finally give up. My client has a Windows Server 2012 Essentials server (with all updates installed - no errors in error logs nor SFC /SCANNOW). Purchased a new Windows 8 Pro computer, wh
-
An error occurred querying a data source - with REST services
Hi, I have a SharePoint 2013 form library library with an info-path form. I need to get the logged in user's 'Display Name' on my form load automatically. I used REST service to fetch the current user details. In the preview mode of the form, its sho
-
Maintainance Duration of BW 3.1 and BW3.5
Hello, i'm just searching for the maintaince Duration of the BW Releases 3.1 and 3.5. Is there a site on the marketplace,where I can find the excact an reliable information. Thanx
-
I have 2 computers and want the same songs,video's and movies on both
I just bought a new mini netbook and want to copy all songs onto the netbook so it mirrors my main desk top computer. I tried the home share, but the library disappears from the net book when I disconnect from my home network.
-
Smartcard Programming on Linux for Newbies - a HOWTO
http://groups.google.com/group/e27-01/browse_thread/thread/fdbacad759599503 enjoy!