0% found this document useful (0 votes)
20 views1 page

Declare @SQL Varchar (1000) Set @filespec '////////Tecra////Tecrac////Temp////T1 - C.TXT' Set @SQL String ('Load Table T1 From ''', @filespec, '''') Execute Immediate @SQL End

The document discusses how to use the LOAD TABLE statement in SQL to load data from an external file into a database table. It describes how escape characters are processed when specifying the file path in the LOAD TABLE statement. It also provides an extensive list of options that control how LOAD TABLE handles checking constraints, computed columns, default values, delimiters, escape characters, file formats, and hexadecimal values.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views1 page

Declare @SQL Varchar (1000) Set @filespec '////////Tecra////Tecrac////Temp////T1 - C.TXT' Set @SQL String ('Load Table T1 From ''', @filespec, '''') Execute Immediate @SQL End

The document discusses how to use the LOAD TABLE statement in SQL to load data from an external file into a database table. It describes how escape characters are processed when specifying the file path in the LOAD TABLE statement. It also provides an extensive list of options that control how LOAD TABLE handles checking constraints, computed columns, default values, delimiters, escape characters, file formats, and hexadecimal values.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Chapter 2: Inserting 59

DECLARE @sql VARCHAR ( 1000 );


SET @filespec = '\\\\\\\\TECRA\\\\TecraC\\\\temp\\\\t1_c.txt';
SET @sql = STRING ( 'LOAD TABLE t1 FROM ''', @filespec, '''' );
EXECUTE IMMEDIATE @sql;
END;
The escape character (\) is processed each time a string is parsed. In the exam-
ple above, each pair of backslashes (\\) is reduced to a single \ as part of that
processing, and it happens twice once when the SET @filespec parses the
string literal, and once when EXECUTE IMMEDIATE parses the command in
@sql. That means each \ you want to survive until the LOAD TABLE actually
runs must be represented by four backslashes in the original string literal, and
for a pair of backslashes to survive, you must code them as eight.
The way LOAD TABLE works is controlled by an extensive list of options,
as follows:
n CHECK CONSTRAINTS OFF disables CHECK constraints while
LOAD TABLE inserts new rows. The default is ON, to check the CHECK
constraints.
n COMPUTES OFF disables the calculation of computed column values
and accepts the input values. The default is ON, to ignore the input values
and calculate the values instead.
n DEFAULTS ON enables the setting of DEFAULT values for columns that
are not being filled from the input file. The default is OFF, to disable col-
umn DEFAULT values; the effect of this is described later in this section.
n DELIMITED BY can be used to change the field delimiter; for example,
DELIMITED BY '\x09' specifies that the input file is tab-delimited. The
default is the comma (,).
n ESCAPE CHARACTER can be used to specify which single character
will be interpreted as the escape character in string literals in the input file
(e.g., ESCAPE CHARACTER '!'). The default is the backslash (\). Note
that this option affects how the input data is processed; it doesnt have any-
thing to do with the way escape characters in the input file specification are
handled.
n ESCAPES OFF can be used to turn off escape character processing alto-
gether so that all characters will be treated as data. The default is ON, to
process escape characters. Once again, this option refers to the data in the
file, not the file specification in the LOAD TABLE statement.
n FORMAT BCP specifies that the special Adaptive Server Enterprise Bulk
Copy Program (bcp.exe) file format is being used by the input file. The
default is FORMAT ASCII for ordinary text files. This book doesnt dis-
cuss the details of FORMAT BCP.
n HEXADECIMAL OFF turns off the interpretation of 0xnnn-style input
values as unquoted binary string literals; the input characters will be stored
as they appear. The default is ON, to interpret 0xnnn-style values as strings
of hexadecimal characters to be converted into strings. For example,
0x414243 will be stored as 0x414243 if HEXADECIMAL is OFF and as
ABC if HEXADECIMAL is ON. This affects both binary and character
columns.

You might also like