when extracting data from SQL Server to files and more specifically to CSV files.
As you can see, records 2 and 3 contain null values.
As you can see on the above screenshot, the output seems correct. The records' NULL values have been replaced with empty strings.
Output:
As you can see, the empty strings have been replaced by NULLs which correspond to the hexadecimal character \x00.
From the MSDN Library article on BCP, we read the following:
- out copies from the database table or view to a file. If you specify an existing file, the file is overwritten. When extracting data, note that the bcp utility represents an empty string as a null and a null string as an empty string.
It seems from the above example, that the queryout keyword has the same behavior regarding null and empty strings.
Now, if you are going to feed the CSV file to another application for parsing and processing it, if the application does not explicitly handle possible occurrences of the NULL character then most probably an error will be occurred.
To this end, always have in mind the above behavior when extracting data to files using BCP.