Solved

How to use Print statement  in Store procedure

Posted on 2007-11-25
5
169 Views
Last Modified: 2010-04-21
I have a store procedure with a Print Statement,

ALTER Procedure [dbo].[sp_ProcessImage]
      @Err int OUTPUT
      
As
declare @rowPro integer      -- 1 row must be Updated
                                                
select @Err = 1      
Begin Tran

INSERT INTO Asset
( .....

select @rowPro = @@rowcount
      
if @rowPro <> 1 or @@error != 0
      begin
            Rollback Tran
            select @Err = 1
            return
      end
Commit Tran
      select @Err = 0      
      return

print 'Rowpro=' + @rowPro


After I run procedure I hope I can get 'Rowpro=1', but I didn't get anyting print out. How I can trace the value of a variable inside procedure?  
0
Comment
Question by:dshi15
  • 2
  • 2
5 Comments
 
LVL 75

Expert Comment

by:Aneesh Retnakaran
ID: 20346325
put the print statement before the 'return statement'


Commit Tran
      select @Err = 0      
 
print 'Rowpro=' + @rowPro

    return
0
 
LVL 1

Author Comment

by:dshi15
ID: 20346358
Hi,
I forgot how to convert int.

print 'Rowpro=' + convert(@rowPro,varchar(25)) is not work. thanks.
0
 
LVL 35

Assisted Solution

by:David Todd
David Todd earned 100 total points
ID: 20347750
Hi,

Your convert is back-to-front

print 'Rowpro = ' + convert( varchar( 25 ), @testInt )

and dont forget to put it _before_ the return!

Cheers
  David
0
 
LVL 75

Accepted Solution

by:
Aneesh Retnakaran earned 150 total points
ID: 20347818
print 'Rowpro=' + cast (@rowPro  as varchar(25))
0
 
LVL 1

Author Closing Comment

by:dshi15
ID: 31410866
thanks
0

Featured Post

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question