Link to home
Start Free TrialLog in
Avatar of Steve Bohler
Steve BohlerFlag for United States of America

asked on

Viewing print output from a Stored Procedure in SQL Server Management Studio

So, I've got Microsoft SQL Server Management Studio 2008.

In the "old" days (earlier version, probably Visual Studio 2005), I had PRINT statements in my stored procedure and I could execute the SP and see all the print statements in an output window.

Now, when I execute a SP, I don't see these print statements, even in the Messages window.

Any suggestions?

Thanks,

Steve
Avatar of Aneesh
Aneesh
Flag of Canada image

Hello skbohler,

its still available with the sql server management studio,




Regards,

aneeshattingal
Avatar of Steve Bohler

ASKER

How?

Where is the output viewed?
try running the stored procedure from sql server mangement studio,

you can test  even running the following statement

print 'hello world'
I think the problem is with print statements that used to work but don't, like:

PRINT CAST(@ITEMID AS CHAR(5)) + ' | ' + CAST(@ITEMTYPEIDENTIFIER AS CHAR) + ' | ' + @ITEMTEXT + ' | ' + CAST(@THRESHOLDLOW AS CHAR) + ' | ' + CAST(@THRESHOLDHIGH AS CHAR) + ' | '  + CAST(@TMPSCORE AS CHAR) + ' | ' + CAST(@UNADJUSTEDSCORE AS CHAR) + ' | ' +  CAST(@RESULT AS CHAR)

If I just try and use:

PRINT @ITEMID + ' | ' @ITEMTYPEIDENTIFIER

it generates an error. That is why I put in the CAST statements, and those work in the output of Visual Studio.

Again, simple PRINT statements do work (like PRINT @ITEMID).

Any ideas why the more complex print statement wouldn't produce any results in Management Studio?

Steve
ASKER CERTIFIED SOLUTION
Avatar of Aneesh
Aneesh
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I'll try that and let you know. Thanks.
Also if they are numeric it wont concatenate either, and it is probably important to see if any of them are NULL

best is open a query window (short cut key CTRL+N) do your declarations, then paste the code :

print isnull(convert(varchar,@ITEMID),'NULL') + '|' + isnull(convert(varchar,@ITEMTYPEIDENTIFIER),'NULL')

then when you run it (shortcut key F5) you should get the tab pages down the bottom - at least one of which will be 'Messages' that is where the print will go (as well as any errors, and other messages, etc).

So as an example try pasting the whole lot (below) and press F5 :

declare @ITEMID int
declare @ITEMTYPEIDENTIFIER int

print isnull(convert(varchar,@ITEMID),'NULL') + '|' + isnull(convert(varchar,@ITEMTYPEIDENTIFIER),'NULL')

set @itemid = 1

print isnull(convert(varchar,@ITEMID),'NULL') + '|' + isnull(convert(varchar,@ITEMTYPEIDENTIFIER),'NULL')

set @itemid = 2
set @itemtypeidentifier = 2

print isnull(convert(varchar,@ITEMID),'NULL') + '|' + isnull(convert(varchar,@ITEMTYPEIDENTIFIER),'NULL')

--results should be three lines in the 'messages' tab (without the leading hyphens of course)
--NULL|NULL
--1|NULL
--2|2