Sybase Technical Library - Product Manuals Home
[Search Forms] [Previous Section with Hits] [Next Section with Hits] [Clear Search] Expand Search

Chapter 11 Using
Destination-Template Transfer [Table of Contents] Chapter 12 Accessing catalog
information with CSPs

Access Service User's Guide DirectConnect for AS/400

[-] Chapter 11 Using Destination-Template Transfer
[-] General description of Destination-Template Transfer

General description of Destination-Template Transfer

The destination-template transfer statement allows you to perform operations that do more than transfer data. You can use destination-template transfer statements to:

When you use the destination-template transfer statement, you can feed a result set into a template, and then force the template to perform certain operations.

During a destination-template transfer, the access service inserts the data values it retrieves with the sourceselectstatement from the source database into the destination-template SQL clause. This clause contains one question mark (?) for each column in the result set of the sourceselectstatement. Each value from the result set is substituted for the corresponding question mark in the template on a row-by-row basis. The access service then executes the resulting statement against the target database.Col1Col2

The following figure shows replacement with numeric and character values. This figure assumes that is numeric and is character.

Figure 11-1: Replacement of values during destination-template transferraster

Syntax for Destination-Template transfer statements

The syntax for a destination-template transfer statement is as follows:

transfer [with
report]
{to | from} 'secondaryname
userid password';
sourceselectstatement;
destinationtemplatestatement

where:

To increase processing efficiency, you can batch destination-templates together for processing. Use the TransferBatch property or set statement to specify how many templates to batch.

Destination-Template datatype qualifiers

Qualifiers tell the access service how to format data that is inserted for a placeholder. If you do not supply a qualifier, the access service applies default transformations.

Qualification is required for date and time values. You can use the ?T, ?t, ?D, and ?d qualifiers for dates, or you can create a custom qualifier using the special qualifiers described in Table 11-5 .

In destination-template transfers, you cannot use the question mark as a literal, except inside quoted strings. The access service recognizes the question mark only as a qualifier.

The following table defines valid datatype qualifiers.

Destination-template transfer datatype qualifiers

Placeholder/ Qualifier

Definition

?C

Character data enclosed in quotes

?N

Numeric data, not quoted

?D

A standard format Adaptive Server datetime data enclosed in quotes: 'MON DD YYYY hh:mm:ss.nnn'

?d

Standard format for AS/400 date in quotes: 'mm/dd/yyyy'

?T

Standard format AS/400 TIMESTAMP data enclosed in quotes: 'YYYY-MM-DD-hh.mm.ss.nnnnnn'

?t

Standard format for AS/400 time in quotes: 'hh:mm:ss'

?X

Standard format Adaptive Server hexadecimal data (for example, 0xffee), used for transferring binary data to Adaptive Server

?x

Standard format AS/400 hexadecimal data (for example, X'FFEE'), used for transferring binary data to AS/400

?y

Standard format for Teradata date in quotes: 'yy/mm/dd'

?O

Standard format for Oracle hexadecimal data, used for transferring binary data to Oracle

Table 11-2 shows the effects of qualifiers ?C, ?N, ?D, and ?T on Open Server datatypes.

Effects of qualifiers on datatypes

Open Server Datatype

Default

Qualifiers (in bold)

?C

?N

?D

?T

CS_CHAR CS_VARCHAR CS_TEXT

?C

Quote

No quote

If the source is ISO TIMESTAMP, it is converted to 'Mon dd yyyy hh:mm:ss:nnn'. If the source is ISO DATE, it converts to 'Mon dd yy'. If the source is ISO TIME, it converts to 'Mon dd yy hh:mm:ss' (using the value from the DefaultDate property as the date portion of the value). Otherwise, it is enclosed in quotes and copied as is.

Convert to Open Server datetime string, quote

If the source is ISO DATE or TIME, the DefaultDate and DefaultTime property values are used to fill in missing information.

Convert to ISO TIMESTAMP, quote

CS_BIT, CS_INT1 CS_INT2 CS_ INT4 CS_REAL CS_FLOAT

?N

Convert to char, quote

Convert to char, no quote

n/a

n/a

CS_MONEY CS_MONEY4 CS_DECIMAL

?N

Convert to char, quote

Convert to char, no quote

n/a

n/a

CS_DATETIME CS_DATETIME4

?D

Using the ?C or ? qualifier from Adaptive Server datetime columns to AS/400 char or varchar columns causes the transferred value to lose precision. Use one of the following workarounds: - Use destination-template with the ?T qualifier. - Use bulk transfer to transfer from Adaptive Server datetime columns to AS/400 timestamp columns. - Use the Adaptive Server convert function in the sourceselectstatement to format the datetime data.

'MON DD YYYY hh:mm' [AM or PM]

n/a

'MMM DD YYYY hh:mm:ss:nnn'

'YYYY-MM-DD-hh.mm.ss.nnnnnn'

CS_BINARY CS_VARBINARY CS_IMAGE

?X or ?x

Convert to hex, quote

n/a

n/a

n/a

Table 11-3 shows the effects of qualifiers ?y, ?d, ?t, and ?x on Open Server datatypes.

Effects of qualifiers on datatypes

?y

?d

?t

?x

CS_CHAR CS_VARCHAR CS_TEXT

?C

If the source is ISO DATE, TIME, or TIMESTAMP, it converts to 'yy/mm/dd'. Otherwise, it is enclosed in quotes and copied as is.

quote

If the source is ISO DATE, TIME, or TIMESTAMP, it converts to 'mm/dd/yy'. Otherwise, it is enclosed in quotes and copied as is.

Quote

If the source is ISO DATE, TIME, or TIMESTAMP, it converts to 'hh:mm:ss'. Otherwise, it is enclosed in quotes and copied as is.

Quote

Convert to hex; leading 'X, trailing 'f

CS_BIT, CS_INT1 CS_INT2 CS_INT4 CS_REAL CS_FLOAT CS_MONEY CS_MONEY4 CS_DECIMAL

?N

n/a

n/a

n/a

n/a

CS_DATETIME CS_DATETIME4

?D

'yy/mm/dd'

'yy/mm/dd'

'hh:mm:ss'

n/a

CS_BINARY CS_VARBINARY CS_IMAGE

?X or ?x

n/a

n/a

n/a

Convert to hex; leading 'X, trailing 'f

Table 11-4 shows the effects of qualifiers ?X and ?O on Open Server datatypes

Effects of qualifiers

?X

?O

CS_CHAR CS_VARCHAR CS_TEXT

Convert to hex; leading 0x, no quote

n/a

CS_BIT, CS_ INT1 CS_INT2 CS_INT4 CS_REAL CS_FLOAT CS_MONEY CS_MONEY4 CS_DECIMAL

?N

n/a

n/a

CS_DATETIME CS_DATETIME4

?D

n/a

n/a

CS_BINARY CS_VARBINARY CS_IMAGE

?X or ?x

If the target database is AS/400, ?x converts the data to the standard AS/400 hex format (a quoted hex number with a leading X).

Convert to hex; leading 0x, no quote

n/a

Special date and time qualifiers

You can combine special date and time qualifiers to construct the date or time format that the target database requires.

Follow these rules for special qualifiers:

The following table shows qualifier definitions.

Special date and time qualifiers for transfer

Qualifier

Definition

yy

Last two digits of year

yyyy

All four digits of year

mm

Month or minute (recognized by context)

mon

Three-character month abbreviation: Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec

dd

Day

hh

Hour

ss

Seconds

mmm

Milliseconds

mmmmmm or uuuuuu

Microseconds

am or pm

Indicates that you want an am or pm designator included. The actual designator is inserted appropriate to the value.

Examples

This section contains examples of destination-template transfer statements executed through ISQL. The following table shows the database and user information used in the examples.

Information used for destination-template transfer examples

Transfer Components

Primary Database

Secondary Database

Database

AS400

Adaptive Server

User ID

as4user

ssuser

Password

as4pass

sspass

Service Name

as4

ss

Table Names

as4table1, as4table2, as4table3

sstable1, sstable2, sstable3

Column Names

as4col1, as4col2, as4col3,...

sscol1, sscol2, sscol3,...

Example #1

Task: Transfer data from certain columns in the AS/400 table named as4table1 to append to the Adaptive Server table named sstable3. Note the specified datatype qualifiers in the sourceselectstatement.

c:>isql -Sas4 -Uas4user -Pas4pass
1>transfer to 'ss ssuser sspass';
2>select as4col1, as4col3, as4col2, as4col6 
3>from as4table1;
4>insert into sstable3 (sscol1,sscol3,sscol2,sscol6) values (?C, ?D, ?C, ?N);
5>go

Result: Data is selected from four columns (ascol1, ascol3, ascol2, ascol6) in the AS/400 table called as4table1 and inserted into the Adaptive Server table called sstable3. Qualifiers (the characters that follow each question mark) are used to ensure that the source values are correctly converted into the target table datatypes. In this example, the template contains four question marks. Therefore, the result set obtained by the sourceselectstatement cannot contain more than four columns or the transfer fails.

Example #2

Task: Select marked rows from an Adaptive Server table and delete the corresponding rows in an AS/400 table.

c:>isql -Sas4 -Uas4user -Pas4pass
1>transfer from 'ss ssuser sspass';
2>select sscol1 from sstable1
3>where action="drop";
4>delete from as4table3
5>where as4col1=?C ;
6>go

Result: Certain rows (those with action set to drop) are selected from sstable1. The column sscol1 is then used to specify the rows to delete in the AS/400 table as4table3, by matching the values with the corresponding AS/400 column as4col1. At this point, you can use an insert statement similar to Example #1 to replace the deleted rows in the AS/400 table with the data from the Adaptive Server table.

Example #3

Task: Update the AS/400 table with data from a similar Adaptive Server table.

c:>isql -Sas4 -Uas4user -Pas4pass
1>transfer from 'ss ssuser sspass';
2>>select sscol1, sscol2, sscol3, sscol4
3>from sstable1
4>where sscol5 > '12/31/1994 24.0000';
5>update as4table3
6>set as4col1=?, as4col2=?, as4col3=? 
7>where as4col4 = ? ;
8>go

Result: Four Adaptive Server columns are selected when sscol5, a datetime value, is greater than a specified date and time ('12/31/24.0000'). The fourth column is the key that specifies the rows to be updated in the AS/400 table called as4table3.

Example #4

Task: Process orders in AS/400 using a stored procedure. The orders were entered in Adaptive Server. Note that the datatype qualifiers are not specified.

c:>isql -Sas4 -Uas4user -Pas4pass
1>transfer from 'ss ssuser sspass';
2>select sscol1, sscol2, sscol3
3>from sstable1;
4>use procedure ordrproc ???;
5>go

Result: The order information is selected from columns in the Adaptive Server table called sstable1, and the stored procedure named ordrproc is executed against the AS/400 to process the information.

Processing Destination-Template transfer from statements

The following figure shows how the transfer from statement updates four columns in the AS/400 table called as4table3 with data selected from four similar Adaptive Server columns. Whether the update occurs depends on a comparison with sscol5, a datetime value that must be greater than '12/31/1994 23.59.000'. The fourth column is the key that specifies the rows targeted for the update.

Figure 11-2: Data flow in a destination-template transfer from statementraster

The following steps describe the data flow process:

Processing Destination-Template transfer to Statements

The following figure shows the transfer to statement appending data from certain columns in the AS/400 table named as4table1 to Adaptive Server table sstable3. The four qualifiers behind the question marks require that the result set from the sourceselectstatement contains four columns; otherwise, the transfer fails.

Figure 11-3: Data flow in a destination-template transfer to statement raster

The following steps describe the data flow process:


Chapter 11 Using
Destination-Template Transfer [Table of Contents] Chapter 12 Accessing catalog
information with CSPs