Writes a text file (.TXT) to disk from a
SELECT query. If the query has multiple columns, they are concatenated
together with no separator. The text is not escaped or quoted.
- filename (string expression)
The absolute path to the text file to write. The file does not need to exist. If it does exist, by default new lines will be appended to it. Use the
TRUNCATE_EXISTING_FILEoption to overwrite the existing file.
SELECTstatement that provides the rows to write to the file.
TRUNCATE_EXISTING_FILE(0 or 1, default: 0)
If the output file exists, this option indicates whether the existing file contents should be deleted.
- 0 = Keep existing file data and append new lines
- 1 = Delete existing file data
FILE_ENCODING(integer 0-65535, default: 0)
Indicates the text encoding to use when writing the text file. Specify 0 to use UTF-8. Any nonzero integer is treated as a Windows code page number.
EXPORT TXT 'C:\MyFile.txt' FROM (SELECT * FROM mytable);
Writes the contents of
mytableinto a file called "MyFile.txt". Because no options are specified, the lines are appended to "MyFie.txt" and the UTF-8 encoding is used.
EXPORT TXT 'C:\MyFile.txt' FROM (SELECT * FROM mytable) OPTIONS (TRUNCATE_EXISTING_FILE: 1);
Overwrite "MyFile.txt" if it already exists.