views:

1591

answers:

6

In SQL Server 2005, I want to print out a blank line with the PRINT statement, however, when I run

PRINT ''

it actually prints a line with a single space.

Does anyone know if it's possible to just print a blank line without the space?

If I print a new line character, it doesn't print a space, but I end up with two new lines.

A: 

AFAIK there is no way around this, it is the way the print statement works

Mitchel Sellers
+4  A: 

You could just add a newline on your previous print statement, if you have one.

Instead of:

PRINT 'BLABLABLA'
PRINT ''

You could write:

PRINT 'BLABLABLA
' <- the string finishes here!
Loris
A: 

Can you encode the BACKSPACE character and PRINT that out?

UPDATE: PRINT '' + CHAR(8) doesn't seem to go down particularly well :(

Rob
A: 

This suggests that you want to print a blank message. Are you sure that this is your intention? The Print statement actually sends a message to the error/message-handling mechanism that then transfers it to the calling application.

A: 

Very similar to the other suggestion here, this seems to work:

print '
'
A: 
-- Search the web for: SQL PRINT NewLine
-- What you'll end up finding:

DECLARE @CR AS CHAR(1)    -- Carriage Return (CR)
DECLARE @LF AS CHAR(1)    -- Line Feed (LF)
DECLARE @CrLf AS CHAR(2)  -- Carriage Return / Line Feed

SET @CR = CHAR(10)
SET @LF = CHAR(13)
SET @CrLf = @CR + @LF

PRINT '--==--==--==--==--=='
PRINT @CrLf + 'Use variables as you see fit' + @CrLf
PRINT '--==--==--==--==--=='

-- AntGut
AntGut