Steve Bohler
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
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
ASKER
How?
Where is the output viewed?
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'
you can test even running the following statement
print 'hello world'
ASKER
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
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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,@IT EMID),'NUL L') + '|' + isnull(convert(varchar,@IT EMTYPEIDEN TIFIER),'N ULL')
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,@IT EMID),'NUL L') + '|' + isnull(convert(varchar,@IT EMTYPEIDEN TIFIER),'N ULL')
set @itemid = 1
print isnull(convert(varchar,@IT EMID),'NUL L') + '|' + isnull(convert(varchar,@IT EMTYPEIDEN TIFIER),'N ULL')
set @itemid = 2
set @itemtypeidentifier = 2
print isnull(convert(varchar,@IT EMID),'NUL L') + '|' + isnull(convert(varchar,@IT EMTYPEIDEN TIFIER),'N ULL')
--results should be three lines in the 'messages' tab (without the leading hyphens of course)
--NULL|NULL
--1|NULL
--2|2
best is open a query window (short cut key CTRL+N) do your declarations, then paste the code :
print isnull(convert(varchar,@IT
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,@IT
set @itemid = 1
print isnull(convert(varchar,@IT
set @itemid = 2
set @itemtypeidentifier = 2
print isnull(convert(varchar,@IT
--results should be three lines in the 'messages' tab (without the leading hyphens of course)
--NULL|NULL
--1|NULL
--2|2
its still available with the sql server management studio,
Regards,
aneeshattingal