有没有办法在 t-sql 中的打印语句之后停止额外的新行? [英] Is there any way to stop the extra new line after a print statement in t-sql?

查看:30
本文介绍了有没有办法在 t-sql 中的打印语句之后停止额外的新行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个小问题,但对我来说太痛苦了.通常,我会编写包含多个查询的存储过程.为了让调试更容易,我是这样写的:

This is a petty question, but is such a pain for me. Often, I will write store procedures with multiple queries in them. To make debugging easier, I write it like so:

print 'Some notes about query 1'
select * from someTable

print 'some notes about query 2'
update sometable set column = null

然后我得到这样的结果:

then I get results like this:

Some notes about query 1

(8 row(s) affected)
Some notes about query 2

(8 row(s) affected)

他们的方式是它自己的空间使其难以阅读.我希望结果如下所示:

They way it spaces itself makes it hard to read. I'd want the results to look like this:

Some notes about query 1
(8 row(s) affected)

Some notes about query 2
(8 row(s) affected)

我知道它很琐碎,但它让我感到厌烦.有人有什么想法吗?

I know its petty, but it irks me. Anyone have any thoughts?

推荐答案

汇总您得到的答案:

--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)'

这篇关于有没有办法在 t-sql 中的打印语句之后停止额外的新行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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