16.10.2015 Views

Getting Started with IBM Data Studio for DB2

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

294 <strong>Getting</strong> <strong>Started</strong> <strong>with</strong> <strong>IBM</strong> <strong>Data</strong> <strong>Studio</strong> <strong>for</strong> <strong>DB2</strong><br />

PRODUCT_CATALOG<br />

This procedure is defined under theGOSALES schema. It returns a result set containing all<br />

products from the catalog <strong>for</strong> a given product type. Using the in<strong>for</strong>mation you learned in<br />

Chapter 8, create the following procedure (you can cut and paste the text below into the<br />

SQL procedure editor). Be sure to deploy it into theGOSALES schema.<br />

CREATE PROCEDURE GOSALES.PRODUCT_CATALOG (IN PRODUCT_TYPE VARCHAR(50))<br />

DYNAMIC RESULT SETS 1<br />

SPECIFIC GOSALES.PRODUCT_CATALOG<br />

------------------------------------------------------------------------<br />

-- SQL Stored Procedure<br />

------------------------------------------------------------------------<br />

P1: BEGIN<br />

-- Declare cursor<br />

DECLARE CURSOR1 CURSOR WITH RETURN FOR<br />

SELECT P.PRODUCT_NUMBER, Q.PRODUCT_NAME,<br />

Q.PRODUCT_DESCRIPTION,<br />

P.PRODUCTION_COST, P.PRODUCT_IMAGE<br />

FROM GOSALES.PRODUCT AS P,<br />

GOSALES.PRODUCT_NAME_LOOKUP AS Q,<br />

GOSALES.PRODUCT_TYPE AS R<br />

WHERE P.PRODUCT_NUMBER = Q.PRODUCT_NUMBER<br />

AND Q.PRODUCT_LANGUAGE = 'EN'<br />

AND R.PRODUCT_TYPE_CODE = P.PRODUCT_TYPE_CODE<br />

AND R.PRODUCT_TYPE_EN = PRODUCT_TYPE;<br />

-- Cursor left open <strong>for</strong> client application<br />

OPEN CURSOR1;<br />

END P1<br />

Listing 10.2 – PRODUCT_CATALOG procedure<br />

10.5.2 SQL statements used in the web service<br />

We use two SQL statements <strong>for</strong> our web service:<br />

<br />

<br />

GetBestSellingProductsByMonth<br />

RankEmployee.<br />

GetBestSellingProductsByMonth<br />

The SQL statement shown in Listing 10.3 returns the top 50 products by shipping numbers<br />

<strong>for</strong> the given month. Using the in<strong>for</strong>mation in Chapter 5, create a new SQL script <strong>with</strong> the<br />

nameGetBestSellingProductsByMonth and copy the below statement into that<br />

script.<br />

SELECT PN.PRODUCT_NAME, PB.PRODUCT_BRAND_EN, SUM(IL.QUANTITY_SHIPPED) AS<br />

NUMBERS_SHIPPED, PN.PRODUCT_DESCRIPTION<br />

FROM GOSALES.INVENTORY_LEVELS AS IL, GOSALES.PRODUCT AS P,<br />

GOSALES.PRODUCT_NAME_LOOKUP AS PN, GOSALES.PRODUCT_BRAND AS PB<br />

WHERE IL.PRODUCT_NUMBER = PN.PRODUCT_NUMBER<br />

AND IL.PRODUCT_NUMBER = P.PRODUCT_NUMBER<br />

AND P.PRODUCT_BRAND_CODE = PB.PRODUCT_BRAND_CODE

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!