Solved

How to use Print statement  in Store procedure

Posted on 2007-11-25
5
163 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

I am showing a way to read/import the excel data in table using SQL server 2005... Suppose there is an Excel file "Book1" at location "C:\temp" with column "First Name" and "Last Name". Now to import this Excel data into the table, we will use…
In this article I will describe the Copy Database Wizard 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.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
I designed this idea while studying technology in the classroom.  This is a semester long project.  Students are asked to take photographs on a specific topic which they find meaningful, it can be a place or situation such as travel or homelessness.…

919 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now