T-SQL 中的 PRINT 语句 [英] PRINT statement in T-SQL

查看:73
本文介绍了T-SQL 中的 PRINT 语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么 T-SQL 中的 PRINT 语句似乎只是有时有效?使用它有什么限制?似乎有时如果生成了一个结果集,它就变成了一个空函数,我假设是为了防止损坏结果集,但是它的输出是否不会在另一个结果集中出现,例如行数?

Why does the PRINT statement in T-SQL seem to only sometimes work? What are the constraints on using it? It seems sometimes if a result set is generated, it becomes a null function, I assumed to prevent corrupting the resultset, but could it's output not go out in another result set, such as the row count?

推荐答案

那么,如果您有类似以下的语句,您是说您没有得到打印"结果?

So, if you have a statement something like the following, you're saying that you get no 'print' result?

select * from sysobjects
PRINT 'Just selected * from sysobjects'

如果您使用 SQL 查询分析器,您会看到底部有两个选项卡,其中一个是消息",打印"语句将在此处显示.
如果您担心看到打印语句的时间,您可能想尝试使用类似

If you're using SQL Query Analyzer, you'll see that there are two tabs down at the bottom, one of which is "Messages" and that's where the 'print' statements will show up.
If you're concerned about the timing of seeing the print statements, you may want to try using something like

raiserror ('My Print Statement', 10,1) with nowait

这将在到达语句时立即为您提供消息,而不是像查询分析器在大多数情况下所做的那样缓冲输出.

This will give you the message immediately as the statement is reached, rather than buffering the output, as the Query Analyzer will do under most conditions.

这篇关于T-SQL 中的 PRINT 语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆