Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

tsql

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?

like image 451
TizzyFoe Avatar asked Dec 22 '11 15:12

TizzyFoe


1 Answers

Putting together the answers you get:

--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)'
like image 187
Mack Avatar answered Oct 23 '22 21:10

Mack