Sql-server – SQLSTATE 01000 in SQL Server job output

sql serversql-server-agent

I've got SQL Server jobs running that include periodic 'print' statements so that I can look in the job history and get a sense of what happened. But the output is cluttered with [SQLSTATE 01000]. Given that there is a limit to how much will fit in this output, I'd like as much space as possible for information I care about.

Is there any way to suppress the [SQLSTATE 01000] output for 'print' commands?

Best Answer

The problem (sorry. "feature") is with the PRINT command in SQL Agent. I've overcome this problem by creating a table variable with one column for 'output' and populating it as I progress through my script, then at the very end of the job SELECT from the table variable. Piping the output to a file through SQL Agent gives me a log of the job. At any point in the job if it encounters an error, I dump the contents of the table before quitting. (I typically include the command to be executed into the table variable immediately before executing it). Simply replacing all your PRINT statements with one SELECT statement at the end of the job will get rid of those pesky [SQLSTATE 01000] suffixes to

every... damn... line...

Cheers, Ken