SQL Server 作业输出中的 SQLSTATE 01000

发布于 2024-07-11 18:29:46 字数 174 浏览 7 评论 0原文

我正在运行包含定期“打印”语句的 SQL Server 作业,以便我可以查看作业历史记录并了解发生的情况。 但输出中充满了 [SQLSTATE 01000]。 鉴于此输出中的容纳量是有限的,我希望为我关心的信息提供尽可能多的空间。

有什么方法可以抑制“打印”命令的 [SQLSTATE 01000] 输出?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

昔梦 2024-07-18 18:29:46

问题(抱歉,“功能”)与 SQL 代理中的 PRINT 命令有关。 我通过创建一个包含一列“输出”的表变量并在执行脚本时填充它来克服这个问题,然后在作业的最后从表变量中选择。 通过 SQL 代理将输出传送到文件会为我提供作业日志。 在作业中的任何时刻,如果遇到错误,我都会在退出之前转储表的内容。 (我通常在执行之前将要执行的命令包含到表变量中)。 只需在作业结束时用一个 SELECT 语句替换所有 PRINT 语句即可消除

每个... 的那些讨厌的 [SQLSTATE 01000] 后缀。
该死...
线...

干杯,

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

国粹 2024-07-18 18:29:46

你可能不走运。 这是 PRINT 语句的正常输出。 我不认为有什么办法可以压制他们。

You're probably out of luck. That is normal output for PRINT statements. I don't think there is any way to suppress them.

三五鸿雁 2024-07-18 18:29:46

如果您只想从输出中删除 [SQLSTATE 01000] 或包含 [SQLSTATE 01000] 的任何内容,则不是肯定的。 所以这里有两种方法。

Print replace(@PrintThis, '[SQLSTATE 01000]', '');

基本上这将替换 [SQLSTATE 01000] 。

接下来使用 CHARINDEX(表达式 1, 表达式 1 [, start_location]),在表达式 2 中搜索表达式 1,如果找到则返回其起始位置。 搜索从 start_location 开始。

@result = CHARINDEX('[SQLSTATE 01000]', @PrintThis)
if (@result > 0)
    Print @PrintThis

所以如果 CHARINDEX < 0 字符串 [SQLSTATE 01000] 不存在,并且不会打印

如果错过了您尝试执行的操作,请按此回复。

我希望这有帮助,

布雷特

Not positive if you wanted to remove just the [SQLSTATE 01000] from the output or anything which contained [SQLSTATE 01000]. So here is both ways.

Print replace(@PrintThis, '[SQLSTATE 01000]', '');

Basically this will replace [SQLSTATE 01000] with nothing.

The next useses CHARINDEX(expression1, expression1 [, start_location]), Searches expression2 for expression1 and returns its starting position if found. The search starts at start_location.

@result = CHARINDEX('[SQLSTATE 01000]', @PrintThis)
if (@result > 0)
    Print @PrintThis

So if CHARINDEX < 0 the string [SQLSTATE 01000] doesn't exist and it doesn't print

If missed what you are trying to do please respond as such.

I hope this helps,

Brett

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文