cognos db2 article

1
-- The following script is provided on an as-is basis only. -- It is designed to be launched from a Windows platform running DB2 9.5 with pureXML. -- The FpML bundle (for FpML 4.2) must be downloaded and executed beforehand. -- Consult the "Resources" section of the IBM developerWorks article for details. -- -- From a DB2 command window, issue the following command: -- db2 -td% -vf CognosDB2Article.db2 -- connect to the database connect to fpml% -- drop the view (in case one was previously created) drop view fpmladmin.creditv% -- use this to create a relational view of XML data -- -- create a view that will contain -- info about credit default swap derivatives that involve a failure to pay by some known entity create view fpmladmin.creditv (tradeDate, entityName, party1, party2, amount, currency) as select t.* from fpmladmin.fpml, xmltable(XMLNAMESPACES(DEFAULT 'http://www.fpml.org/2005/FpML-4-2'),'$DOCUMENT/FpML' columns tradeDate date path 'trade/tradeHeader/tradeDate', entityName varchar(80) path 'trade/creditDefaultSwap/generalTerms/referenceInformation/referenceEntity/entityName', party1 varchar(80) path 'party[1]/partyName', party2 varchar(80) path 'party[2]/partyName', amount varchar(30) path 'trade/creditDefaultSwap/protectionTerms/creditEvents/failureToPay/paymentRequirement/amount', currency varchar(10) path 'trade/creditDefaultSwap/protectionTerms/creditEvents/failureToPay/paymentRequirement/currency' ) as t where productid like 'credit%' and xmlexists ('declare default element namespace "http://www.fpml.org/2005/FpML-4-2"; $DOCUMENT/FpML/trade/creditDefaultSwap/protectionTerms/creditEvents/failureToPay/paymentRequirement') and xmlexists ('declare default element namespace "http://www.fpml.org/2005/FpML-4-2"; $DOCUMENT/FpML/trade/creditDefaultSwap/generalTerms/referenceInformation/referenceEntity/entityName')% -- test that you can use the view select * from fpmladmin.creditv% -- sample SQL/XML query -- -- this retrieves the text XML nodes of the trade IDs -- for all credit swaps involving 1 of 2 referenced entities select xmlserialize(content xmlquery('declare default element namespace "http://www.fpml.org/2005/FpML-4-2"; $fpml/FpML/trade/tradeHeader/partyTradeIdentifier[1]/tradeId/text()' passing document as "fpml") as varchar(25) ) tradeID1, xmlserialize(content xmlquery('declare default element namespace "http://www.fpml.org/2005/FpML-4-2"; $fpml/FpML/trade/tradeHeader/partyTradeIdentifier[2]/tradeId/text()' passing document as "fpml") as varchar(25) ) tradeID2 from fpmladmin.fpml where xmlexists('declare default element namespace "http://www.fpml.org/2005/FpML-4-2"; $fpml/FpML/trade/creditDefaultSwap/generalTerms/referenceInformation/referenceEntity[entityName="Amcor Ltd" or "Abbey National PLC"]' passing document as "fpml" )% Page 1 of 1 9/3/2010 http://download.boulder.ibm.com/ibmdl/pub/software/dw/dm/db2/dm-0811saracco/Cognos...

Upload: crystalrhoades

Post on 07-Apr-2015

32 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Cognos DB2 Article

-- The following script is provided on an as-is basis only.

-- It is designed to be launched from a Windows platform running DB2 9.5 with pureXML.

-- The FpML bundle (for FpML 4.2) must be downloaded and executed beforehand.

-- Consult the "Resources" section of the IBM developerWorks article for details.

--

-- From a DB2 command window, issue the following command:

-- db2 -td% -vf CognosDB2Article.db2

-- connect to the database

connect to fpml%

-- drop the view (in case one was previously created)

drop view fpmladmin.creditv%

-- use this to create a relational view of XML data

--

-- create a view that will contain

-- info about credit default swap derivatives that involve a failure to pay by some known entity

create view fpmladmin.creditv (tradeDate, entityName, party1, party2, amount, currency) as

select t.* from fpmladmin.fpml,

xmltable(XMLNAMESPACES(DEFAULT 'http://www.fpml.org/2005/FpML-4-2'),'$DOCUMENT/FpML'

columns

tradeDate date path 'trade/tradeHeader/tradeDate',

entityName varchar(80) path

'trade/creditDefaultSwap/generalTerms/referenceInformation/referenceEntity/entityName',

party1 varchar(80) path 'party[1]/partyName',

party2 varchar(80) path 'party[2]/partyName',

amount varchar(30) path

'trade/creditDefaultSwap/protectionTerms/creditEvents/failureToPay/paymentRequirement/amount',

currency varchar(10) path

'trade/creditDefaultSwap/protectionTerms/creditEvents/failureToPay/paymentRequirement/currency'

)

as t where productid like 'credit%'

and xmlexists ('declare default element namespace "http://www.fpml.org/2005/FpML-4-2";

$DOCUMENT/FpML/trade/creditDefaultSwap/protectionTerms/creditEvents/failureToPay/paymentRequirement')

and xmlexists ('declare default element namespace "http://www.fpml.org/2005/FpML-4-2";

$DOCUMENT/FpML/trade/creditDefaultSwap/generalTerms/referenceInformation/referenceEntity/entityName')%

-- test that you can use the view

select * from fpmladmin.creditv%

-- sample SQL/XML query

--

-- this retrieves the text XML nodes of the trade IDs

-- for all credit swaps involving 1 of 2 referenced entities

select xmlserialize(content

xmlquery('declare default element namespace "http://www.fpml.org/2005/FpML-4-2";

$fpml/FpML/trade/tradeHeader/partyTradeIdentifier[1]/tradeId/text()' passing document as "fpml")

as varchar(25) ) tradeID1,

xmlserialize(content

xmlquery('declare default element namespace "http://www.fpml.org/2005/FpML-4-2";

$fpml/FpML/trade/tradeHeader/partyTradeIdentifier[2]/tradeId/text()' passing document as "fpml")

as varchar(25) ) tradeID2

from fpmladmin.fpml

where xmlexists('declare default element namespace "http://www.fpml.org/2005/FpML-4-2";

$fpml/FpML/trade/creditDefaultSwap/generalTerms/referenceInformation/referenceEntity[entityName="Amcor Ltd" or "Abbey National PLC"]'

passing document as "fpml"

)%

Page 1 of 1

9/3/2010http://download.boulder.ibm.com/ibmdl/pub/software/dw/dm/db2/dm-0811saracco/Cognos...