这是一个小问题,但对我来说真是太痛苦了。通常,我会在其中编写包含多个查询的存储过程。为了使调试更容易,我这样写:
print 'Some notes about query 1'
select * from someTable
print 'some notes about query 2'
update sometable set column = null
然后我得到这样的结果:
Some notes about query 1
(8 row(s) affected)
Some notes about query 2
(8 row(s) affected)
它们的空间本身使它难以阅读。我希望结果看起来像这样:
Some notes about query 1
(8 row(s) affected)
Some notes about query 2
(8 row(s) affected)
我知道它很小,但它让我很烦。有人有什么想法吗?
答案 0 :(得分:12)
汇总你得到的答案:
--Set up test data
DECLARE @someTable AS TABLE(id int identity, somevalue int)
INSERT INTO @someTable (somevalue) VALUES (1)
INSERT INTO @someTable (somevalue) VALUES (2)
INSERT INTO @someTable (somevalue) VALUES (3)
INSERT INTO @someTable (somevalue) VALUES (4)
INSERT INTO @someTable (somevalue) VALUES (5)
INSERT INTO @someTable (somevalue) VALUES (6)
INSERT INTO @someTable (somevalue) VALUES (7)
INSERT INTO @someTable (somevalue) VALUES (8)
--Here's the method.
SET NOCOUNT ON --As kd7 said this will get rid of spaces. Along with the rowcount.
print 'Some notes about query 1'
select * from @someTable
print '(' + CONVERT(varchar,@@rowcount) +' row(s) affected)'--This adds the row count back in
print '' --Formatting row to add the space you require.
print 'Some notes about query 2'
update @sometable set somevalue = null
print '(' + CONVERT(varchar,@@rowcount) +' row(s) affected)'
答案 1 :(得分:4)
设置NOCOUNT ON将删除空格,但也会删除(受影响的8行),不确定这是否适合你。
答案 2 :(得分:1)
如果您需要输出中的行计数 - 那么在SSMS中没有任何决定,否则使用set nocount on
<强> BUT 强>
你总是可以编写自己的应用程序来运行这些查询,并使用自己的输出包括rowcounts