SQL Notebook (logo)

READ_FILE_TEXT Function

Reads the contents of a text file and returns it as a single string representing the whole file.

Syntax

READ_FILE_TEXT(file-path, [file-encoding])

Arguments

Return Value

Text.

Examples

  1. DECLARE @data = READ_FILE_TEXT('C:\MyFile.txt');
    Reads the contents of "MyFile.txt" into a text variable called @data. Because the file-encoding parameter is not specified, the UTF-8 encoding is used to read the file.
  2. SELECT READ_FILE_TEXT('C:\ShiftJIS.txt', 932) AS data;
    Produces a 1-row query result containing the contents of "ShiftJIS.txt", which is read using the Japanese Shift-JIS encoding (code page 932).