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

标签 tsql

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

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

关于tsql - 有没有办法在 t-sql 中的打印语句之后停止额外的新行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8606084/

相关文章:

sql - 通过重命名旧表,然后填充新版本,将表停机时间降至最低?

tsql - 设置 SQL Server 语法

sql - 提取字符串中的最后一个数字

显示总数的 SQL 查询

sql-server-2005 - 为什么将 WHERE 子句放在 View 之外的性能很差

tsql - SQL Server 数据库更改部署

sql - SQL触发器: On update of primary key,如何确定哪个 “deleted”记录对应于哪个 “inserted”记录?

sql - 正确使用计数功能

sql-server - SQL Server 中存储 IP 地址的数据类型

sql - MS-Access 中同一字段中两种类型值的计数