Search code examples
sqlsql-serverbcp

Is it possible to export 'PRINT' commands into a file via bcp?


I want to export a result of a PRINT command. I don't want to use the normal SQL Server logs. Is that possible with bcp? Because the following command does not work.

Example:

SET @IPE = 'bcp PRINT ''Test''  queryout ' + @Path + '1b_Log_change_log_entry.txt -c -T'

Result:

Starting copy...
SQLState = S1000, NativeError = 0
Error = [Microsoft][ODBC Driver 13 for SQL Server]BCP host-files must contain at least one column
SQLState = S1000, NativeError = 0
Error = [Microsoft][ODBC Driver 13 for SQL Server]Unable to resolve column level collations
NULL
BCP copy out failed
NULL

Solution

  • Print is not a query but Select is.. Try Select instead of Print

    SET @IPE = 'bcp SELECT ''Test''  queryout ' + @Path + '1b_Log_change_log_entry.txt -c -T'