加入收藏 | 设为首页 | 会员中心 | 我要投稿 安卓应用网 (https://www.0791zz.com/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 数据库 > MsSql > 正文

tsql – 有没有办法在t-sql中的print语句后停止额外的新行?

发布时间:2020-05-24 16:47:43 所属栏目:MsSql 来源:互联网
导读:这是一个小问题,但对我来说真是太痛苦了.通常,我会在其中编写包含多个查询的存储过程.为了使调试更容易,我这样写: print Some notes about query 1select * from someTableprint some notes about query 2update sometable set column = null 然后我得到这样

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

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)

我知道它很小,但它让我很烦.有人有什么想法?

解决方法

汇总你得到的答案:
--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)'

(编辑:安卓应用网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读