THE SQL Server Blog Spot on the Web

Welcome to SQLblog.com - The SQL Server blog spot on the web Sign in | |
in Search

Denis Gobo

SQL Teaser: Printing Without Using PRINT

Print the @SQL variable without using PRINT

DECLARE @SQL varchar(49)

SELECT @SQL = 'Print This Now ' + CONVERT(VARCHAR(30), GETDATE())

--Your Code Here

Published Friday, November 09, 2007 1:59 PM by Denis Gobo
Filed under:

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

 

Matt said:

SELECT @SQL

November 9, 2007 1:36 PM
 

Vern Rabe said:

How about:

RAISERROR (@SQL, 10,1) WITH NOWAIT;

November 9, 2007 1:37 PM
 

Denis Gobo said:

yep, RAISERROR will do it

November 9, 2007 1:41 PM
 

Linchi Shea said:

I guess that depends on what you meant by 'Printing without using PRINT".

If you mean doing what exactly the same as appears to the client code, PRINT and RAISERROR are very different if you are using DB Library. One is handled through a message handler and the other through a error handler. If you are talking about presenting the same message to the end user, then anything that returns a sting back to the client code will do.

November 10, 2007 9:01 AM
 

Denis Gobo said:

Linchi,

I meant running it in QA/SSMS and getting the same result as using print without using print. I guess I should have been clearer (I am like a business requirement lately....not clear at all)  ;-(

November 10, 2007 9:38 AM
 

David R Buckingham said:

I use RAISERROR( @SQL, 0, 1 ) WITH NOWAIT a lot, particularly if I want output from inside a transaction regardless of whether it commits or rolls back.  Just be careful of overuse since it immediately transmits to the client.

November 12, 2007 9:19 AM

Leave a Comment

(required) 
(required) 
Submit

About Denis Gobo

I was born in Croatia in 1970, when I was one I moved to Amsterdam (and yes Ajax is THE team in Holland) and finally in 1993 I came to the US. I have lived in New York City for a bunch of years and currently live in Princeton, New Jersey with my wife and 3 kids. I work for Dow Jones as a Database architect in the indexes department, one drawback: since our data goes back all the way to May 1896 I cannot use smalldates ;-( I have been working with SQL server since version 6.5 and compared to all the other bloggers here I am a n00b. Some of you might know me from http://sqlservercode.blogspot.com/ or even from some of the newsgroups where I go by the name Denis the SQL Menace If you are a Tek-Tips user then you might know me by the name SQLDenis, I am one of the guys answering SQL Questions in the SQL Programming forum.

This Blog

Syndication

Powered by Community Server (Commercial Edition), by Telligent Systems
  Privacy Statement