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

Chapter 10 Using Bulk Copy Transfer [Table of Contents] Chapter 12 Accessing catalog
information with CSPs

Access Service User's Guide DirectConnect

[-] Chapter 11 Using Destination-Template Transfer

Chapter 11

Using Destination-Template Transfer

This chapter describes the destination-template transfer statement and covers the following topics:

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.

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

Figure 11-1: Replacement of values during destination-template transfer raster

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. 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

A SQL Server char or DB2 CHAR data string enclosed in quotes

?N

Numeric data, not quoted

?D

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

?d

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

?T

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

?t

Standard format for DB2 time in quotes: 'hh:mm:ss'

?X

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

?x

Standard format DB2 hexadecimal data (for example, X'FFEE')--used for transferring binary data toDB2

?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 , Table 11-3 , and Table 11-4 show the effects of qualifiers on Open Server datatypes.

Effects of qualifiers on datatypes (?C, ?N, ?D, ?T),

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 an ISO TIMESTAMP, it is converted to 'Mon dd yyyy hh:mm:ss:nnn'. If the source is an ISO DATE, it is converted to 'Mon dd yy'. If the source is an ISO TIME, it is converted to 'Mon dd yy hh:mm:ss' (using the value from the Default Date property as the date portion of the value). Otherwise, it is enclosed in quotes and copied as is. If the target DBMS is a SQL Server, strings that do not convert to DATE, TIMESTAMP, or TIME are not transferred.

Convert to Open Server datetime string, quote

If the source is an 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

'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

The following table shows the effects of qualifiers on Open Server datatypes.

Effects of qualifiers on datatypes (?y, ?d, ?t, ?x),

Open Server Datatype

Default

Qualifiers (in bold)

?y

?d

?t

?x

CS_CHAR CS_VARCHAR CS_TEXT

?C

If the source is an ISO DATE, TIME, or TIMESTAMP, it is converted to 'yy/mm/dd'. Otherwise, it is enclosed in quotes and copied as is. Strings that do not convert to DATE, TIMESTAMP, or TIME are not transferred.

If the source is an ISO DATE, TIME, or TIMESTAMP, it is converted to 'mm/dd/yy'. Otherwise, it is enclosed in quotes and copied as is. Strings that do not convert to DATE, TIMESTAMP, or TIME are not transferred.

If the source is an ISO DATE, TIME, or TIMESTAMP, it is converted to 'hh:mm:ss'. Otherwise, it is enclosed in quotes and copied as is. Strings that do not convert to DATE, TIMESTAMP, or TIME are not transferred.

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

The following table shows the effects of qualifiers on Open Server datatypes.

Effects of qualifiers on datatypes (?X, ?O,),

Open Server Datatype

Default

Qualifiers (in bold)

?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 DB2, ?x converts the data to the standard DB2 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

DB2

SQL Server

User ID

db2user

ssuser

Password

db2pass

sspass

Service Name

db2

ss

Table Names

db2table1, db2table2, db2table3

sstable1, sstable2, sstable3

Column Names

db2col1, db2col2, db2col3,....

sscol1, sscol2, sscol3,...

Example #1

Task: Transfer data from certain columns in the DB2 table named db2table1 to append to the SQL Server table named sstable3. Note the specified datatype qualifiers in the sourceselectstatement.

c:>isql -Sdb2 -Udb2user -Pdb2pass
1>transfer to 'ss ssuser sspass';
2>select db2col1, db2col3, db2col2, db2col6
3>from db2table1;
4>insert into sstable3 (sscol1,sscol3,sscol2,sscol6) values (?C, ?D, ?C, ?N);
5>go

Result: Data is selected from four columns(db2col1, db2col3, db2col2, db2col6) in the DB2 table called db2table1and inserted into the SQL 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 a SQL Server table and delete the corresponding rows in a DB2 table.

c:>isql -Sdb2 -Udb2user -Pdb2pass
1>transfer from 'ss ssuser sspass';
2>select sscol1 from sstable1
3>where action="drop";
4>delete from db2table3
5>where db2col1=?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 DB2 table db2table3, by matching the values with the corresponding DB2 column db2col1. At this point, you can use an insert statement similar to example #1 to replace the deleted rows in the DB2 table with the data from the SQL Server table.

Example #3

Task: Update the DB2 table with data from a similar SQL Server table.

c:>isql -Sdb2 -Udb2user -Pdb2pass
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 db2table3
6>set db2col1=?, db2col2=?, db2col3=?
7>where db2col4 = ? ;
8>go

Result: Four SQL 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 DB2 table called dbtable3.

Example #4

Task: Process orders in DB2 using an RSP. The orders were entered in SQL Server. Note that the datatype qualifiers are not specified.

c:>isql -Sdb2 -Udb2user -Pdb2pass
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 SQL Server table called sstable1, and the RSP named ordrproc is executed against DB2 to process the information.

Processing Destination-Template transfer from Statements

The following figure shows how the transfer from statementupdates four columns in the DB2 table called db2table3 with data selected from four similar SQL 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 DB2 table named db2table1 to SQL 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 10 Using Bulk Copy Transfer [Table of Contents] Chapter 12 Accessing catalog
information with CSPs