Home » SQL & PL/SQL » SQL & PL/SQL » HELP! Insert Script
HELP! Insert Script [message #219387] |
Wed, 14 February 2007 03:57 |
kipp@plancknet.com
Messages: 25 Registered: September 2006
|
Junior Member |
|
|
I have 2 INSERT scripts, they are in the same sql file and run one after the other, ie,
INSERT INTO tableA
...
COMMIT;
INSERT INTO tableA
...
COMMIT;
What I need to do and just figure out is the second insert is almost the same as the first, but I only want to run it if tableA is empty. I need to check it in the WHERE statement as I am not using PL/SQL and cant use IF's.
Can anyone help with this?
Thanks!
|
|
|
|
|
|
|
Re: HELP! Insert Script [message #219490 is a reply to message #219392] |
Wed, 14 February 2007 11:25 |
kipp@plancknet.com
Messages: 25 Registered: September 2006
|
Junior Member |
|
|
Ok, what I am tryin to do below, create a blank temp table,
then insert the data into the temp where sysdate-1,
next INSERT the data into the temp table if there was no data inserted using sysdate-1, then insert into the temp tab le using sysdate-2.
CREATE TABLE ODS_BSM_ISSUES_TEMP AS
SELECT * FROM ODS_ISSUE_TRANS WHERE row_num=1;
COMMIT;
DELETE ODS_BSM_ISSUES_TEMP;
COMMIT;
--
INSERT INTO ODS_BSM_ISSUES_TEMP
(seq_num,
doc_num,
nsn,
dashesnsn,
sfx_cd,
qty,
fsc,
stat_dt,
stat_cd,
dodaac,
addrs,
stat_dt_999,
supplemental_address,
multi,
prod_cd,
lbsshipped,
own_purp_cd,
cond_cd,
sig_cd,
supp_addr,
serv_type,
qty_oh,
cd_ind,
display_prod_cd,
display_doc_num,
display_service,
display_stat_dt_999,
display_qty,
display_stat_cd,
display_sfx_cd,
shipto_address,
report_date
)
(SELECT
seq_ods_issue.nextval,
RQN.zzorig_doc_NBR,
RQN.nsn,
substr(RQN.nsn,1,4)||'-'||substr(RQN.nsn,5,2)||'-'||substr(RQN.nsn,7,3)||'-'||substr(RQN.nsn,10,4),
RQN.suffix,
RQN.quantity,
RQN.fsc,
RQN.dob,
RQN.status_cd,
SUBSTR(RQN.zzorig_doc_NBR,1,6),
NVL(DOD.user_address,'NO ADDRESS ON FILE'),
to_char(RQN.dob,'YDDD'),
RQN.ZZSUPP_ADRS,
LK.wt_cmp_number*LK.wt_factor,
LK.display_prod_cd,
LK.wt_cmp_number*RQN.quantity*LK.wt_factor,
NULL,
NULL,
NVL(RQN.zzsig_cd,NULL),
NULL, --- SUPP_
'X', --- LK.SERV_TYPE Pre-populate with dummy
NULL, --- LK.QTY_OH,
LK.cd_ind,
LK.display_prod_cd,
RQN.zzorig_doc_NBR,
'XXXXXXXXXXX', --- display_service Pre-populate with dummy
to_char(RQN.dob,'YDDD'),
RQN.quantity,
RQN.status_cd,
RQN.suffix,
NULL,
to_char(dob,'MONTH YYYY')
FROM ZDOR_RQH RQN,
ODS_ADDRESS DOD,
ODS_NSN_LOOKUP LK
WHERE SUBSTR(RQN.zzorig_doc_NBR,1,6) NOT IN (SELECT ods.dodaac
FROM ODS_EX_DODAAC_LOOKUP ods
WHERE ods.dodaac=substr(RQN.zzorig_doc_NBR,1,6))
AND RQN.nsn = LK.nsn
AND RQN.DATA_DATE = to_date(sysdate-1,'DD-MON-YY')
AND SUBSTR(RQN.zzorig_doc_NBR,1,6) = DOD.dodaac (+));
COMMIT;
--
PROMPT ** Now check the Data_date-2 if there are no records for Data_date-1
--
INSERT INTO ODS_BSM_ISSUES_TEMP
(seq_num,
doc_num,
nsn,
dashesnsn,
sfx_cd,
qty,
fsc,
stat_dt,
stat_cd,
dodaac,
addrs,
stat_dt_999,
supplemental_address,
multi,
prod_cd,
lbsshipped,
own_purp_cd,
cond_cd,
sig_cd,
supp_addr,
serv_type,
qty_oh,
cd_ind,
display_prod_cd,
display_doc_num,
display_service,
display_stat_dt_999,
display_qty,
display_stat_cd,
display_sfx_cd,
shipto_address,
report_date
)
(SELECT
seq_ods_issue.nextval,
RQN.zzorig_doc_NBR,
RQN.nsn,
substr(RQN.nsn,1,4)||'-'||substr(RQN.nsn,5,2)||'-'||substr(RQN.nsn,7,3)||'-'||substr(RQN.nsn,10,4),
RQN.suffix,
RQN.quantity,
RQN.fsc,
RQN.dob,
RQN.status_cd,
SUBSTR(RQN.zzorig_doc_NBR,1,6),
NVL(DOD.user_address,'NO ADDRESS ON FILE'),
to_char(RQN.dob,'YDDD'),
RQN.ZZSUPP_ADRS,
LK.wt_cmp_number*LK.wt_factor,
LK.display_prod_cd,
LK.wt_cmp_number*RQN.quantity*LK.wt_factor,
NULL,
NULL,
NVL(RQN.zzsig_cd,NULL),
NULL, --- SUPP_
'X', --- LK.SERV_TYPE Pre-populate with dummy
NULL, --- LK.QTY_OH,
LK.cd_ind,
LK.display_prod_cd,
RQN.zzorig_doc_NBR,
'XXXXXXXXXXX', --- display_service Pre-populate with dummy
to_char(RQN.dob,'YDDD'),
RQN.quantity,
RQN.status_cd,
RQN.suffix,
NULL,
to_char(dob,'MONTH YYYY')
FROM ZDOR_RQH RQN,
ODS_ADDRESS DOD,
ODS_NSN_LOOKUP LK
WHERE (SELECT * FROM dual
WHERE 0=(SELECT COUNT(0) FROM tableA))
AND SUBSTR(RQN.zzorig_doc_NBR,1,6) NOT IN (SELECT ods.dodaac
FROM ODS_EX_DODAAC_LOOKUP ods
WHERE ods.dodaac=substr(RQN.zzorig_doc_NBR,1,6))
AND RQN.nsn = LK.nsn
AND RQN.DATA_DATE = to_date(sysdate-2,'DD-MON-YY')
AND SUBSTR(RQN.zzorig_doc_NBR,1,6) = DOD.dodaac (+));
COMMIT;
|
|
|
Re: HELP! Insert Script [message #219511 is a reply to message #219490] |
Wed, 14 February 2007 12:47 |
joy_division
Messages: 4963 Registered: February 2005 Location: East Coast USA
|
Senior Member |
|
|
kipp@plancknet.com wrote on Wed, 14 February 2007 12:25 | ...
AND RQN.DATA_DATE = to_date(sysdate-1,'DD-MON-YY')
...
AND RQN.DATA_DATE = to_date(sysdate-2,'DD-MON-YY')
|
As I have told you before, but I guess you do not listen.
sysdate is already a DATE and hence, you do not use TO_DATE on it.
[Updated on: Wed, 14 February 2007 12:49] Report message to a moderator
|
|
|
Goto Forum:
Current Time: Wed Dec 04 18:51:44 CST 2024
|