Is there a way to stop an extra new line after a print statement in t-sql?

This is a petty question, but for me it is such a pain. Often I will write storage procedures with several requests to them. To make debugging easier, I write it like this:

print 'Some notes about query 1' select * from someTable print 'some notes about query 2' update sometable set column = null 

then I get the following results:

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

As he runs through himself, it is difficult to read. I 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 his little thing, but it annoys me. Anyone have any thoughts?

+7
source share
3 answers

Combining the answers received:

 --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 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)' 
+11
source

Setting NOCOUNT ON will remove the space, but also delete (the affected 8 lines), not sure if this will be viable for you.

+4
source

If you need rowcounts on the output, then there is no solution in SSMS, otherwise use set nocount on

BUT

you can always write your own application to run these queries with your own output, including rowcounts

+1
source

All Articles