13.01.2013 Views

OpenEdge Data Management: DataServer for Microsoft SQL Server

OpenEdge Data Management: DataServer for Microsoft SQL Server

OpenEdge Data Management: DataServer for Microsoft SQL Server

SHOW MORE
SHOW LESS

Create successful ePaper yourself

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

RDBMS Stored Procedure Details<br />

3–26<br />

Details about a dynamic temp-table in a prepared state<br />

Example 3–14 shows multiple dynamic temp-tables in a prepared state. The temp tables, tt1<br />

and tt2, are prepared in the code just be<strong>for</strong>e the RUN STORED-PROC statement is called and the<br />

temp-tables are passed. The temp-table definition is considered prepared because of the explicit<br />

inclusion of each field name and associated data type.<br />

/* example - Multiple dynamic temp-tables in a prepared state*/<br />

DEFINE VARIABLE tt1 AS HANDLE NO-UNDO.<br />

DEFINE VARIABLE tt2 AS HANDLE NO-UNDO.<br />

DEFINE VARIABLE tt-array AS HANDLE NO-UNDO EXTENT 2.<br />

CREATE TEMP-TABLE tt1.<br />

tt1:ADD-NEW-FIELD(“custnum”, “integer”).<br />

tt1:ADD-NEW-FIELD(“name”, “character”).<br />

/*no more fields will be added */<br />

tt1:TEMP-TABLE-PREPARE (“ordx1”).<br />

CREATE TEMP-TABLE tt2.<br />

tt2:ADD-NEW-FIELD(“ordernum”, “integer”).<br />

tt2:ADD-NEW-FIELD(“orderdate”, “date”).<br />

/*no more fields will be added */<br />

tt2:TEMP-TABLE-PREPARE (“ordx2”).<br />

ASSIGN<br />

tt-array[1] = tt1<br />

tt-array[2] = tt2.<br />

RUN STORED-PROC myproc LOAD-RESULT-INTO tt-array (INPUT 10, INPUT “order”).<br />

Example 3–14: Multiple temp-tables in a prepared state<br />

In the previous dynamic temp-table example, note that the temp-table definitions must match<br />

the result set that the send-sql- statement returns. For example, the number of fields and the data<br />

type of each field in the result must have a corresponding field defined in the temp-table that<br />

will receive the result set. No mapping exists between the result set and the temp-table.<br />

There<strong>for</strong>e, the first field defined in the temp-table corresponds to the first column of the result<br />

set and so <strong>for</strong>th.<br />

Additional temp-table examples<br />

This section presents more examples that show various techniques to code temp-tables.<br />

Example 3–15 follows this initial explanation; the stored procedure myProc is comprised of two<br />

fields—one is an integer and the other is a character, and a result set.<br />

SELECT “myProc,” cust_num, cust_name FROM <br />

Example 3–15: Temp-table code technique

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

Saved successfully!

Ooh no, something went wrong!