How can I get this PL/SQL Statement to run from an excel macro?
And I also need to be able to change the "from date" and "to date" from cells in excel. It's a Oracle 8 database.
-- select trade info (standard contracts) about trades that are in delivery during selected period
select
'STD ' AS CType,
sp.tradeid,
0 as Detailsid,
'N/A' as portfolioid,
sp.accountcode,
sp.counterparty,
sp.power,
-- sp.power * p.totalhours,
sp.price,
sp.currencycode,
sp.physical,
sp.productid ,
sp.audited,
p.totalhours,
p.startdate,
p.enddate
from kw4_sptrades sp, kw4_standardprod p
where
sp.productid = p.standardproductid and
sp.physical = 0 and accountcode <>'ND' and
(
(p.startdate between to_date('01.10.2003','dd.mm.yyyy') and to_date('31.10.2003','dd.mm.yyyy') or
p.enddate between to_date('01.10.2003','dd.mm.yyyy') and to_date('31.10.2003','dd.mm.yyyy')
) or
(p.startdate < to_date('01.10.2003','dd.mm.yyyy') and p.enddate > to_date('31.10.2003','dd.mm.yyyy') )
)
UNION
select
'NONSTD' AS CType,
ch.tradeid,
cd.detailsid as Detailsid,
ch.portfolioid as portfolioid,
ch.accountcode,
ch.counterparty,
cd.power,
-- cd.power * cd.totalhours,
cd.price,
ch.currencycode,
ch.physical,
ch.productid ,
ch.audited,
cd.totalhours,
cd.startdate,
cd.enddate
from kw4_contractsheader ch, kw4_contractsdetails cd
where
ch.portfolioid = cd.portfolioid and
ch.physical = 0 and
accountcode <>'ND' and
(
(cd.startdate between to_date('01.10.2003','dd.mm.yyyy') and to_date('31.10.2003','dd.mm.yyyy') or
cd.enddate between to_date('01.10.2003','dd.mm.yyyy') and to_date('31.10.2003','dd.mm.yyyy')
) or
(cd.startdate < to_date('01.10.2003','dd.mm.yyyy') and cd.enddate > to_date('31.10.2003','dd.mm.yyyy') )
)
order by tradeid
;
And I also need to be able to change the "from date" and "to date" from cells in excel. It's a Oracle 8 database.
-- select trade info (standard contracts) about trades that are in delivery during selected period
select
'STD ' AS CType,
sp.tradeid,
0 as Detailsid,
'N/A' as portfolioid,
sp.accountcode,
sp.counterparty,
sp.power,
-- sp.power * p.totalhours,
sp.price,
sp.currencycode,
sp.physical,
sp.productid ,
sp.audited,
p.totalhours,
p.startdate,
p.enddate
from kw4_sptrades sp, kw4_standardprod p
where
sp.productid = p.standardproductid and
sp.physical = 0 and accountcode <>'ND' and
(
(p.startdate between to_date('01.10.2003','dd.mm.yyyy') and to_date('31.10.2003','dd.mm.yyyy') or
p.enddate between to_date('01.10.2003','dd.mm.yyyy') and to_date('31.10.2003','dd.mm.yyyy')
) or
(p.startdate < to_date('01.10.2003','dd.mm.yyyy') and p.enddate > to_date('31.10.2003','dd.mm.yyyy') )
)
UNION
select
'NONSTD' AS CType,
ch.tradeid,
cd.detailsid as Detailsid,
ch.portfolioid as portfolioid,
ch.accountcode,
ch.counterparty,
cd.power,
-- cd.power * cd.totalhours,
cd.price,
ch.currencycode,
ch.physical,
ch.productid ,
ch.audited,
cd.totalhours,
cd.startdate,
cd.enddate
from kw4_contractsheader ch, kw4_contractsdetails cd
where
ch.portfolioid = cd.portfolioid and
ch.physical = 0 and
accountcode <>'ND' and
(
(cd.startdate between to_date('01.10.2003','dd.mm.yyyy') and to_date('31.10.2003','dd.mm.yyyy') or
cd.enddate between to_date('01.10.2003','dd.mm.yyyy') and to_date('31.10.2003','dd.mm.yyyy')
) or
(cd.startdate < to_date('01.10.2003','dd.mm.yyyy') and cd.enddate > to_date('31.10.2003','dd.mm.yyyy') )
)
order by tradeid
;